Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
oybek committed Sep 20, 2023
1 parent 0ff8456 commit 2b51186
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions spendbook/index.html
Original file line number Diff line number Diff line change
@@ -1,62 +1,65 @@
<!DOCTYPE html>
<html>

<head>
<head>
<link rel="stylesheet" type="text/css" href="../css/main.css" />
</head>

<body>
<div>
<form>
<label for="category">Категория траты</label>
<select id="category" name="category"></select>
<label for="amount">Сумма траты</label>
<input type="number" id="amount" name="amount" placeholder="Сумма" />
<textarea id="text" name="text" placeholder="Комментарий" rows="5"></textarea>
</form>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="js/dropDowns.js"></script>
<script>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="./js/dropDowns.js"></script>
<script>
$(document).ready(function () {
function collectData() {
const data = {
category: $("#category").val(),
amount: parseInt($("#amount").val(), 10),
description: $("#text").val(),
};
Object.keys(data).forEach(
(key) =>
(data[key] =
data[key] === "any" || data[key] === "" ? null : data[key])
);
if (data.category && data.amount) {
enableSubmit(true);
} else {
enableSubmit(false);
}
return data;
function collectData() {
const data = {
category: $("#category").val(),
amount: parseInt($("#amount").val(), 10),
description: $("#text").val(),
};
Object.keys(data).forEach(
(key) =>
(data[key] =
data[key] === "any" || data[key] === "" ? null : data[key])
);
if (data.category && data.amount) {
enableSubmit(true);
} else {
enableSubmit(false);
}
$("#category").on("change", collectData);
$("#amount").on("input", collectData);
return data;
}
$("#category").on("change", collectData);
$("#amount").on("input", collectData);

const mainButton = window.Telegram.WebApp.MainButton;
mainButton.text = "Отправить";
mainButton.enable();
mainButton.onClick(function () {
window.Telegram.WebApp.sendData(JSON.stringify(collectData()));
});
const mainButton = window.Telegram.WebApp.MainButton;
mainButton.text = "Отправить";
mainButton.enable();
mainButton.onClick(function () {
window.Telegram.WebApp.sendData(JSON.stringify(collectData()));
});

function enableSubmit(activate) {
if (activate) {
mainButton.show();
} else {
mainButton.hide();
}
function enableSubmit(activate) {
if (activate) {
mainButton.show();
} else {
mainButton.hide();
}
}
});
</script>
</script>

</html>
<body>
<div>
<form>
<label for="category">Категория траты</label>
<select id="category" name="category"></select>
<label for="amount">Сумма траты</label>
<input type="number" id="amount" name="amount" placeholder="Сумма" />
<textarea
id="text"
name="text"
placeholder="Комментарий"
rows="5"
></textarea>
</form>
</div>
</body>
</html>

0 comments on commit 2b51186

Please sign in to comment.