Skip to content

Commit

Permalink
Merge pull request #1 from wolfrepos/date_input
Browse files Browse the repository at this point in the history
Date input
  • Loading branch information
a-khakimov committed Oct 7, 2023
2 parents 43cc3bd + 1f409ec commit a79fc82
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
14 changes: 14 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@ div {
.input-group input:not(:last-child) {
border-bottom: none; /* Prevent double borders */
}

#date_input {
width: 100%;
padding: 2vw;
margin: 2vw 0;
display: inline-block;
border-radius: 1vw;
box-sizing: border-box;
font-size: var(--font-size);

border: 1px solid var(--border-color);
background-color: var(--bg-color-2);
color: var(--fg-color);
}
21 changes: 20 additions & 1 deletion spendbook/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
category: category,
amount: parseInt($("#amount").val(), 10),
description: $("#text").val(),
date: $("#date_input").val()
};
Object.keys(data).forEach(
(key) =>
Expand All @@ -30,9 +31,25 @@
}
return data;
}

function formatDate(date) {
var d = new Date(date),
month = "" + (d.getMonth() + 1),
day = "" + d.getDate(),
year = d.getFullYear();

if (month.length < 2) month = "0" + month;
if (day.length < 2) day = "0" + day;

return [year, month, day].join("-");
}

$("#date_input").val(formatDate(new Date()));

$("#category").on("change", collectData);
$("#custom_input").on("input", collectData);
$("#amount").on("input", collectData);
$("#date_input").on("change", collectData);

$("#custom_label").hide();
$("#custom_input").hide();
Expand Down Expand Up @@ -79,8 +96,10 @@
id="text"
name="text"
placeholder="Комментарий"
rows="5"
rows="3"
></textarea>
<label for="amount">Дата</label>
<input type="date" id="date_input">
</form>
</div>
</body>
Expand Down

0 comments on commit a79fc82

Please sign in to comment.