IMPR: JS validate Min/max length

This commit is contained in:
Tony Air 2020-10-12 21:40:17 +07:00
parent b175062400
commit 53befbb036

View File

@ -56,12 +56,17 @@ const FormValidateField = (($) => {
console.warn(`${NAME}: Browser check validity is failed #${$el.attr('id')}`); console.warn(`${NAME}: Browser check validity is failed #${$el.attr('id')}`);
} }
let unmaskedVal = val;
if(typeof $el.inputmask === 'function'){
unmaskedVal = $el.inputmask('unmaskedvalue');
}
// required // required
if ( if (
$el.hasClass('required') && $el.hasClass('required') &&
(!val.length || (!unmaskedVal.length ||
!val.trim().length || !unmaskedVal.trim().length ||
(ui.isHtml(val) && !$(val).text().length)) (ui.isHtml(val) && !$(unmaskedVal).text().length))
) { ) {
valid = false; valid = false;
console.warn(`${NAME}: Required field is missing #${$el.attr('id')}`); console.warn(`${NAME}: Required field is missing #${$el.attr('id')}`);
@ -76,11 +81,6 @@ const FormValidateField = (($) => {
console.warn(`${NAME}: Wrong URL #${$el.attr('id')}`); console.warn(`${NAME}: Wrong URL #${$el.attr('id')}`);
} }
let unmaskedVal = val;
if(typeof $el.inputmask === 'function'){
unmaskedVal = $el.inputmask('unmaskedvalue');
}
// maxlength // maxlength
const maxLength = $el.attr('maxlength'); const maxLength = $el.attr('maxlength');
if(maxLength && maxLength.length) { if(maxLength && maxLength.length) {