Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 0f95db9

Browse files
hubert-derivHubert Koster
andauthored
Hubert / e-mail input wouldn't show error after making valid e-mail address invalid again. (#6684)
* fixing clearError function hiding the wrong element. * changing regex * allow capital letters * refactoring code * refactoring code * refactoring code * refactoring code * refactoring code * updating regex * adjusting regex * adjusting regex * updating regex * updating regex * updating regex Co-authored-by: Hubert Koster <hubertkoster@Huberts-MacBook-Pro.local>
1 parent bd744f2 commit 0f95db9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/javascript/app/common/form_validation.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ const Validation = (() => {
164164
// ----- Validation Methods -----
165165
// ------------------------------
166166

167-
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);
167+
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);
168+
168169
const validRequired = (value, options, field) => {
169170
if (value.length) return true;
170171
// else
@@ -318,8 +319,8 @@ const Validation = (() => {
318319
}
319320

320321
let all_is_ok = true;
321-
let message = '';
322322
const field_type = field.$.attr('type');
323+
let message_template = '';
323324

324325
field.validations.some((valid) => {
325326
if (!valid) return false; // check next validation
@@ -350,13 +351,13 @@ const Validation = (() => {
350351
}
351352

352353
if (!field.is_ok) {
353-
message = options.message || ValidatorsMap.get(type).message;
354+
message_template = options.message || ValidatorsMap.get(type).message;
354355
if (type === 'length') {
355-
message = template(message, [options.min === options.max ? options.min : `${options.min}-${options.max}`]);
356+
message_template = template(message_template, [options.min === options.max ? options.min : `${options.min}-${options.max}`]);
356357
} else if (type === 'min') {
357-
message = template(message, [options.min]);
358+
message_template = template(message_template, [options.min]);
358359
} else if (type === 'not_equal') {
359-
message = template(message, [options.name1, options.name2]);
360+
message_template = template(message_template, [options.name1, options.name2]);
360361
}
361362
all_is_ok = false;
362363
return true; // break on the first error found
@@ -365,7 +366,7 @@ const Validation = (() => {
365366
});
366367

367368
if (!all_is_ok) {
368-
showError(field, message);
369+
showError(field, message_template);
369370
} else {
370371
clearError(field);
371372
}
@@ -382,11 +383,10 @@ const Validation = (() => {
382383
}
383384
};
384385

385-
const showError = (field, localized_message) => {
386-
if (field.$error.html() === localized_message && field.$error.is(':visible')) return;
387-
clearError(field);
386+
const showError = (field, message) => {
388387
Password.removeCheck(field.selector);
389-
field.$error.html(localized_message).setVisibility(1);
388+
field.$error.text(message);
389+
field.$error.setVisibility(1);
390390
};
391391

392392
const validate = (form_selector) => {

0 commit comments

Comments
 (0)