Remove textContent check for non-textarea elements (#1066)
This commit is contained in:
parent
60b1b5eec5
commit
9f9e1dbd91
|
@ -2,17 +2,24 @@ import Validator from 'lib-app/validations/validator';
|
|||
import _ from 'lodash';
|
||||
|
||||
class LengthValidator extends Validator {
|
||||
constructor(length, errorKey = 'INVALID_VALUE', validator = null) {
|
||||
constructor(length, errorKey = 'INVALID_VALUE', validator = null, useHTMLDiv = false) {
|
||||
super(validator);
|
||||
|
||||
this.minlength = length;
|
||||
this.errorKey = errorKey;
|
||||
this.useHTMLDiv = useHTMLDiv;
|
||||
}
|
||||
|
||||
validate(value = '', form = {}) {
|
||||
let div = document.createElement("div");
|
||||
div.innerHTML = value;
|
||||
let text = div.textContent || div.innerText || "";
|
||||
let text;
|
||||
if (this.useHTMLDiv) {
|
||||
let div = document.createElement("div");
|
||||
div.innerHTML = value;
|
||||
text = div.textContent || div.innerText || "";
|
||||
} else {
|
||||
text = value;
|
||||
}
|
||||
|
||||
if(_.every(text, c => c === " ")) {
|
||||
text = text.replace(/\s/g, '');
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ import RepeatPasswordValidator from 'lib-app/validations/repeat-password-validat
|
|||
import LengthValidator from 'lib-app/validations/length-validator';
|
||||
import ListValidator from 'lib-app/validations/list-validator';
|
||||
import ImageSizeValidator from 'lib-app/validations/image-size-validator';
|
||||
import SpaceValidator from './space-validator';
|
||||
|
||||
let validators = {
|
||||
'DEFAULT': new Validator(),
|
||||
'NAME': new LengthValidator(2, 'ERROR_NAME'),
|
||||
'TITLE': new LengthValidator(1, 'ERROR_TITLE'),
|
||||
'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'),
|
||||
'REPEAT_PASSWORD': new RepeatPasswordValidator(),
|
||||
'URL': new LengthValidator(5, 'ERROR_URL'),
|
||||
|
|
Loading…
Reference in New Issue