-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
oybek
committed
Sep 20, 2023
1 parent
0ff8456
commit 2b51186
Showing
1 changed file
with
55 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |