Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
templates/overview_year_month.html: prevent default form actions
Browse files Browse the repository at this point in the history
Fix for PR #110
  • Loading branch information
ShoshinNikita committed Jun 6, 2020
1 parent 9b4f943 commit 6584c0e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions templates/overview_year_month.html
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@
// Incomes

function addIncome() {
preventDefault(this);

const income = replaceCommas(getValue("new-income-income"));
if (isNaN(income)) {
processError("income must be a number");
Expand All @@ -1004,6 +1006,8 @@
}

function editIncome(id) {
preventDefault(this);

const income = replaceCommas(getValue("modal-window__edit-income__income"));
if (isNaN(income)) {
processError("income must be a number");
Expand All @@ -1021,6 +1025,8 @@
}

function removeIncome(id) {
preventDefault(this);

if (!confirm("Do you really want to delete the Income?")) {
return;
}
Expand All @@ -1032,6 +1038,8 @@
// Monthly Payments

function addMonthlyPayment() {
preventDefault(this);

// Skip check because user can't specify typeID as not a number
const typeID = getValue("new-monthly-payment-type");

Expand All @@ -1053,6 +1061,8 @@
}

function editMonthlyPayment(id) {
preventDefault(this);

// Skip check because user can't specify typeID as not a number
const typeID = getValue("modal-window__edit-monthly-payment__type");

Expand All @@ -1074,6 +1084,8 @@
}

function removeMonthlyPayment(id) {
preventDefault(this);

if (!confirm("Do you really want to delete the Monthly Payment?")) {
return;
}
Expand All @@ -1085,6 +1097,8 @@
// Spends

function addSpend(dayID) {
preventDefault(this);

// Skip check because user can't specify typeID as not a number
const typeID = getValue(`new-spend-type-${dayID}`);

Expand All @@ -1106,6 +1120,8 @@
}

function editSpend(id) {
preventDefault(this);

// Skip check because user can't specify typeID as not a number
const typeID = getValue("modal-window__edit-spend__type");

Expand All @@ -1127,6 +1143,8 @@
}

function removeSpend(id) {
preventDefault(this);

if (!confirm("Do you really want to delete the Spend?")) {
return;
}
Expand All @@ -1141,6 +1159,8 @@
var spendTypeChanged = false;

function addSpendType() {
preventDefault(this);

const name = getValue("new-spend-type-name");
if (name === "") {
processError("Name of Spend Type can't be empty");
Expand All @@ -1156,6 +1176,8 @@
}

function editSpendType(id, oldName) {
preventDefault(this);

const newName = getValue(`edit-spend-type-name-${id}`);
if (newName === oldName) {
// Do nothing
Expand Down Expand Up @@ -1366,6 +1388,15 @@
// Helpers
// ----------------------------------------------------

/**
* preventDefault prevent the default action if it is possible
*/
function preventDefault(that) {
if (that.event && that.event.preventDefault) {
that.event.preventDefault();
}
}

/**
* @param {string} elemID - id of an element
* @return {Object} value of an element or empty string
Expand Down

0 comments on commit 6584c0e

Please sign in to comment.