From 61da33618866d03e482de5d93fb5057bff0fd3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 8 Aug 2020 11:25:51 +0800 Subject: [PATCH] Added the validateRecord() validation in the JavaScript of the transaction form, so that users have to explicitly delete the invalid records before submitting the form in the accounting application. --- .../static/accounting/js/transaction-form.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/accounting/static/accounting/js/transaction-form.js b/accounting/static/accounting/js/transaction-form.js index 9808e3b..dbc9b02 100644 --- a/accounting/static/accounting/js/transaction-form.js +++ b/accounting/static/accounting/js/transaction-form.js @@ -338,6 +338,12 @@ function resetRecordButtons() { function validateForm() { let isValidated = true; isValidated = isValidated && validateDate(); + $(".debit-record").each(function () { + isValidated = isValidated && validateRecord(this); + }); + $(".credit-account").each(function () { + isValidated = isValidated && validateRecord(this); + }); $(".record-account").each(function () { isValidated = isValidated && validateAccount(this); }); @@ -374,6 +380,18 @@ function validateDate() { return true; } +/** + * Validates the record. + * + * @param {HTMLLIElement} record the record + * @returns {boolean} true if the validation succeed, or false + * otherwise + * @private + */ +function validateRecord(record) { + return !record.classList.contains("list-group-item-danger"); +} + /** * Validates the account column. *