Remove textContent check for non-textarea elements (#1066)

This commit is contained in:
Ivan Diaz 2021-10-21 12:09:13 -03:00 committed by GitHub
parent 60b1b5eec5
commit 9f9e1dbd91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -2,17 +2,24 @@ import Validator from 'lib-app/validations/validator';
import _ from 'lodash'; import _ from 'lodash';
class LengthValidator extends Validator { class LengthValidator extends Validator {
constructor(length, errorKey = 'INVALID_VALUE', validator = null) { constructor(length, errorKey = 'INVALID_VALUE', validator = null, useHTMLDiv = false) {
super(validator); super(validator);
this.minlength = length; this.minlength = length;
this.errorKey = errorKey; this.errorKey = errorKey;
this.useHTMLDiv = useHTMLDiv;
} }
validate(value = '', form = {}) { validate(value = '', form = {}) {
let div = document.createElement("div"); let text;
div.innerHTML = value; if (this.useHTMLDiv) {
let text = div.textContent || div.innerText || ""; let div = document.createElement("div");
div.innerHTML = value;
text = div.textContent || div.innerText || "";
} else {
text = value;
}
if(_.every(text, c => c === " ")) { if(_.every(text, c => c === " ")) {
text = text.replace(/\s/g, ''); text = text.replace(/\s/g, '');
} }

View File

@ -4,14 +4,13 @@ import RepeatPasswordValidator from 'lib-app/validations/repeat-password-validat
import LengthValidator from 'lib-app/validations/length-validator'; import LengthValidator from 'lib-app/validations/length-validator';
import ListValidator from 'lib-app/validations/list-validator'; import ListValidator from 'lib-app/validations/list-validator';
import ImageSizeValidator from 'lib-app/validations/image-size-validator'; import ImageSizeValidator from 'lib-app/validations/image-size-validator';
import SpaceValidator from './space-validator';
let validators = { let validators = {
'DEFAULT': new Validator(), 'DEFAULT': new Validator(),
'NAME': new LengthValidator(2, 'ERROR_NAME'), 'NAME': new LengthValidator(2, 'ERROR_NAME'),
'TITLE': new LengthValidator(1, 'ERROR_TITLE'), 'TITLE': new LengthValidator(1, 'ERROR_TITLE'),
'EMAIL': new EmailValidator(), 'EMAIL': new EmailValidator(),
'TEXT_AREA': new ImageSizeValidator(undefined, new LengthValidator(1, 'ERROR_CONTENT_SHORT')), 'TEXT_AREA': new ImageSizeValidator(undefined, new LengthValidator(1, 'ERROR_CONTENT_SHORT', true)),
'PASSWORD': new LengthValidator(6, 'ERROR_PASSWORD'), 'PASSWORD': new LengthValidator(6, 'ERROR_PASSWORD'),
'REPEAT_PASSWORD': new RepeatPasswordValidator(), 'REPEAT_PASSWORD': new RepeatPasswordValidator(),
'URL': new LengthValidator(5, 'ERROR_URL'), 'URL': new LengthValidator(5, 'ERROR_URL'),