From 87a2e4ca7f601eea255eeefff8151f51f1ae5ceb Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Thu, 15 Jul 2021 09:46:37 +0200 Subject: [PATCH 01/14] fixing clearError function hiding the wrong element. --- src/javascript/app/common/form_validation.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index fa3c8341084dd..541a2d3dac068 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,8 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^(([a-zA-Z0-9][^!@£$%^&*=/?§±~<>(){}[\]\\.,;:\s@"'`]+(\.[^!@£$%^&*=/?§±~<>(){}[\]\\.,;:\s@"'`]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,}))$/.test(value); + const validEmail = value => /^(([a-zA-Z0-9][^!@£$%^&*=/?§±~<>(){}[\]\\.,;:\s"'`]+(\.[^!@£$%^&*=/?§±~<>(){}[\]\\.,;:\s"'`]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,}))$/.test(value); + const validRequired = (value, options, field) => { if (value.length) return true; // else @@ -363,15 +364,15 @@ const Validation = (() => { if (!all_is_ok) { showError(field, message); } else { - clearError(field); + clearError(field, message); } return all_is_ok; }; - const clearError = (field) => { + const clearError = (field, localized_message) => { if (field.$error && field.$error.length) { - field.$error.setVisibility(0); + field.$error.html(localized_message).setVisibility(0); if (field.$submit_btn_error && field.$submit_btn_error.length) { field.$submit_btn_error.setVisibility(0); } From 7f723dafb7ef23b7d2f8b0b6ac29fb5a014875c6 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Tue, 20 Jul 2021 11:31:32 +0200 Subject: [PATCH 02/14] changing regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 541a2d3dac068..49bda3cd4ea1d 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^(([a-zA-Z0-9][^!@£$%^&*=/?§±~<>(){}[\]\\.,;:\s"'`]+(\.[^!@£$%^&*=/?§±~<>(){}[\]\\.,;:\s"'`]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,}))$/.test(value); + const validEmail = value => /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From 7d7d5b789f72e5ac2464e3a3e9f4c392b3781c0a Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Tue, 20 Jul 2021 11:38:43 +0200 Subject: [PATCH 03/14] allow capital letters --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 49bda3cd4ea1d..6aaed888bd08c 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From cf5ddb024fd1cb99ec89b32cdaa23513f1653ea9 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 28 Jul 2021 12:01:37 +0200 Subject: [PATCH 04/14] refactoring code --- src/javascript/app/common/form_validation.js | 27 ++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 6aaed888bd08c..01dce1e268fad 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -315,7 +315,6 @@ const Validation = (() => { } let all_is_ok = true; - let message = ''; const field_type = field.$.attr('type'); field.validations.some((valid) => { @@ -347,13 +346,17 @@ const Validation = (() => { } if (!field.is_ok) { - message = options.message || ValidatorsMap.get(type).message; + let message_template; + field.$error.text(options.message || ValidatorsMap.get(type).message); if (type === 'length') { - message = template(message, [options.min === options.max ? options.min : `${options.min}-${options.max}`]); + message_template = template('', [options.min === options.max ? options.min : `${options.min}-${options.max}`]); + field.$error.text(message_template); } else if (type === 'min') { - message = template(message, [options.min]); + message_template = template('', [options.min]); + field.$error.text(message_template); } else if (type === 'not_equal') { - message = template(message, [options.name1, options.name2]); + message_template = template('', [options.name1, options.name2]); + field.$error.text(message_template); } all_is_ok = false; return true; // break on the first error found @@ -362,28 +365,26 @@ const Validation = (() => { }); if (!all_is_ok) { - showError(field, message); + showError(field); } else { - clearError(field, message); + clearError(field); } return all_is_ok; }; - const clearError = (field, localized_message) => { + const clearError = (field) => { if (field.$error && field.$error.length) { - field.$error.html(localized_message).setVisibility(0); + field.$error.setVisibility(0); if (field.$submit_btn_error && field.$submit_btn_error.length) { field.$submit_btn_error.setVisibility(0); } } }; - const showError = (field, localized_message) => { - if (field.$error.html() === localized_message) return; - clearError(field); + const showError = (field) => { Password.removeCheck(field.selector); - field.$error.html(localized_message).setVisibility(1); + field.$error.setVisibility(1); }; const validate = (form_selector) => { From c6befcc55a79a45ebd4ef66599923f4d788e21af Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Wed, 28 Jul 2021 12:08:30 +0200 Subject: [PATCH 05/14] refactoring code --- src/javascript/app/common/form_validation.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 01dce1e268fad..41079efb468eb 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -315,6 +315,7 @@ const Validation = (() => { } let all_is_ok = true; + const message = ''; const field_type = field.$.attr('type'); field.validations.some((valid) => { @@ -349,13 +350,13 @@ const Validation = (() => { let message_template; field.$error.text(options.message || ValidatorsMap.get(type).message); if (type === 'length') { - message_template = template('', [options.min === options.max ? options.min : `${options.min}-${options.max}`]); + message_template = template(message, [options.min === options.max ? options.min : `${options.min}-${options.max}`]); field.$error.text(message_template); } else if (type === 'min') { - message_template = template('', [options.min]); + message_template = template(message, [options.min]); field.$error.text(message_template); } else if (type === 'not_equal') { - message_template = template('', [options.name1, options.name2]); + message_template = template(message, [options.name1, options.name2]); field.$error.text(message_template); } all_is_ok = false; From b2af36db66ae0c9f952086949b76b5ea1d307cac Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Thu, 29 Jul 2021 10:06:28 +0200 Subject: [PATCH 06/14] refactoring code --- src/javascript/app/common/form_validation.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 41079efb468eb..62f2494931307 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -315,7 +315,6 @@ const Validation = (() => { } let all_is_ok = true; - const message = ''; const field_type = field.$.attr('type'); field.validations.some((valid) => { @@ -347,19 +346,16 @@ const Validation = (() => { } if (!field.is_ok) { - let message_template; - field.$error.text(options.message || ValidatorsMap.get(type).message); + let message_template = options.message || ValidatorsMap.get(type).message; if (type === 'length') { - message_template = template(message, [options.min === options.max ? options.min : `${options.min}-${options.max}`]); - field.$error.text(message_template); + message_template = template('', [options.min === options.max ? options.min : `${options.min}-${options.max}`]); } else if (type === 'min') { - message_template = template(message, [options.min]); - field.$error.text(message_template); + message_template = template('', [options.min]); } else if (type === 'not_equal') { - message_template = template(message, [options.name1, options.name2]); - field.$error.text(message_template); + message_template = template('', [options.name1, options.name2]); } all_is_ok = false; + field.$error.text(message_template); return true; // break on the first error found } return false; // check next validation From 08e7c658171d8eb450e40004ee815b0e73407aeb Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Thu, 29 Jul 2021 12:13:49 +0200 Subject: [PATCH 07/14] refactoring code --- src/javascript/app/common/form_validation.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 62f2494931307..e8b636815cbb6 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -316,6 +316,7 @@ const Validation = (() => { let all_is_ok = true; const field_type = field.$.attr('type'); + let message_template; field.validations.some((valid) => { if (!valid) return false; // check next validation @@ -346,7 +347,7 @@ const Validation = (() => { } if (!field.is_ok) { - let message_template = options.message || ValidatorsMap.get(type).message; + message_template = options.message || ValidatorsMap.get(type).message; if (type === 'length') { message_template = template('', [options.min === options.max ? options.min : `${options.min}-${options.max}`]); } else if (type === 'min') { @@ -355,14 +356,13 @@ const Validation = (() => { message_template = template('', [options.name1, options.name2]); } all_is_ok = false; - field.$error.text(message_template); return true; // break on the first error found } return false; // check next validation }); if (!all_is_ok) { - showError(field); + showError(field, message_template); } else { clearError(field); } @@ -379,8 +379,9 @@ const Validation = (() => { } }; - const showError = (field) => { + const showError = (field, message) => { Password.removeCheck(field.selector); + field.$error.text(message); field.$error.setVisibility(1); }; From 23b4c87a23174b2d6596ea84bdafd3494d305b4f Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Mon, 2 Aug 2021 09:19:42 +0200 Subject: [PATCH 08/14] refactoring code --- src/javascript/app/common/form_validation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index e8b636815cbb6..51969845579f3 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -316,7 +316,7 @@ const Validation = (() => { let all_is_ok = true; const field_type = field.$.attr('type'); - let message_template; + let message_template = ''; field.validations.some((valid) => { if (!valid) return false; // check next validation @@ -349,11 +349,11 @@ const Validation = (() => { if (!field.is_ok) { message_template = options.message || ValidatorsMap.get(type).message; if (type === 'length') { - message_template = template('', [options.min === options.max ? options.min : `${options.min}-${options.max}`]); + message_template = template(message_template, [options.min === options.max ? options.min : `${options.min}-${options.max}`]); } else if (type === 'min') { - message_template = template('', [options.min]); + message_template = template(message_template, [options.min]); } else if (type === 'not_equal') { - message_template = template('', [options.name1, options.name2]); + message_template = template(message_template, [options.name1, options.name2]); } all_is_ok = false; return true; // break on the first error found From 119e0421d32fd6345e50530a23b17aac802272e1 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Mon, 2 Aug 2021 11:54:59 +0200 Subject: [PATCH 09/14] updating regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 51969845579f3..efcb2794e626a 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From 27380dc37949456e76f5c720c216e8a8bad1f0c4 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Mon, 2 Aug 2021 15:40:36 +0200 Subject: [PATCH 10/14] adjusting regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index efcb2794e626a..10b5a5ac04af2 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*(.)\1+)[a-zA-Z0-9.+_-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From 5b822a990ae55bebabf2b273fc778023265d437d Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Tue, 3 Aug 2021 11:28:32 +0200 Subject: [PATCH 11/14] adjusting regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 10b5a5ac04af2..07088c3ce4c8a 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*(.)\1+)[a-zA-Z0-9.+_-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From 34534b141da8428c1ec8d4d01629271af99ecdcf Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Tue, 3 Aug 2021 12:15:47 +0200 Subject: [PATCH 12/14] updating regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index 07088c3ce4c8a..e3458ef2a8dff 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*[^.+_-]@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From 6a71b4acb452b802f6e6a7378f43e39c46b0195a Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Tue, 3 Aug 2021 13:10:52 +0200 Subject: [PATCH 13/14] updating regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index e3458ef2a8dff..dac0869b51ac0 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*[^.+_-]@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*[a-zA-Z0-9]@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true; From 9e43808a661b309889b3bbd71266fe8837b47db0 Mon Sep 17 00:00:00 2001 From: Hubert Koster Date: Tue, 3 Aug 2021 14:00:12 +0200 Subject: [PATCH 14/14] updating regex --- src/javascript/app/common/form_validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascript/app/common/form_validation.js b/src/javascript/app/common/form_validation.js index dac0869b51ac0..6052ba882bf83 100644 --- a/src/javascript/app/common/form_validation.js +++ b/src/javascript/app/common/form_validation.js @@ -160,7 +160,7 @@ const Validation = (() => { // ----- Validation Methods ----- // ------------------------------ - const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*[a-zA-Z0-9]@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]){1,}?$/.test(value); + const validEmail = value => /^[a-zA-Z0-9]+(?:(?!.*([.+_-])\1+)[a-zA-Z0-9.+_-]+)*[a-zA-Z0-9]@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z](?:[a-zA-Z-]*[a-zA-Z]){1,}?$/.test(value); const validRequired = (value, options, field) => { if (value.length) return true;