add check for decimal expenses before submit expense

This commit is contained in:
steeven 2024-04-14 08:54:26 +02:00
parent 90f610a3d3
commit 7b8b9309ef
1 changed files with 14 additions and 6 deletions

View File

@ -61,6 +61,13 @@ export class ExpenseModal extends Modal {
if (value.includes(",")) { if (value.includes(",")) {
value = value.replace(",", "."); value = value.replace(",", ".");
} }
// Check if the value is a decimal number
const decimalRegex = /^\d+(\.\d+)?$/;
if (!decimalRegex.test(value)) {
new Notice("Please enter a valid decimal number");
return;
}
this.expenseAmount = value; this.expenseAmount = value;
}) })
); );
@ -149,9 +156,10 @@ export class ExpenseModal extends Modal {
); );
// submit button // submit button
new Setting(contentEl).addButton((btn) => // todo: focus sur boutton submit lorsque touche enter hit
btn
.setButtonText("Submit") new Setting(contentEl).addButton((btn) => {
btn.setButtonText("Submit")
.setCta() .setCta()
.onClick(() => { .onClick(() => {
// check if all fields are filled // check if all fields are filled
@ -161,7 +169,6 @@ export class ExpenseModal extends Modal {
this.expenseAccount && this.expenseAccount &&
this.expenseValue this.expenseValue
) { ) {
new Notice("Expense added");
this.close(); this.close();
this.onSubmit( this.onSubmit(
this.expenseAmount, this.expenseAmount,
@ -200,9 +207,10 @@ export class ExpenseModal extends Modal {
new Notice("Please fill all the fields"); new Notice("Please fill all the fields");
return; return;
} }
}) });
); });
} }
onClose() { onClose() {
const { contentEl } = this; const { contentEl } = this;
contentEl.empty(); contentEl.empty();