Errores solucionados

This commit is contained in:
Juan Ferrer Toribio 2017-05-26 13:14:47 +02:00
parent f6888af74a
commit a73b2eba0d
3 changed files with 12 additions and 6 deletions

View File

@ -11,3 +11,4 @@ rules:
guard-for-in: 0
camelcase: 0
default-case: 0
no-eq-null: 0

View File

@ -14,12 +14,15 @@ export const validators = {
min: conf.min || conf.is,
max: conf.max || conf.is
};
if (!validator.isLength(value, options)) {
if (conf.is)
if (conf.is || conf.min === conf.max)
throw new Error(`Value should be ${conf.is} characters long`);
else
else if (conf.min !== conf.max)
throw new Error(`Value should have a length between ${conf.min} and ${conf.max}`);
else if (conf.min)
throw new Error(`Value should have at least ${conf.min} characters`);
else
throw new Error(`Value should have at most ${conf.min} characters`);
}
},
numericality: function(value, conf) {
@ -79,7 +82,9 @@ export function validate(value, conf) {
let validator = validators[conf.validation];
try {
checkNull(value, conf);
if (validator) validator(value, conf);
if (validator && value != null)
validator(value, conf);
} catch (e) {
let message = conf.message ? conf.message : e.message;
throw new Error(message);
@ -93,7 +98,7 @@ export function validate(value, conf) {
* @param {Object} conf The validation configuration
*/
export function checkNull(value, conf) {
if (typeof value === 'undefined') {
if (typeof value === 'undefined' || value === '') {
if (!conf.allowBlank)
throw new Error(`Value can't be blank`);
} else if (value === null && !conf.allowNull)

View File

@ -45,7 +45,7 @@ export default class Textfield extends Component {
this.showClear(this.input.value);
}
showClear(show) {
show = document.activeElement === this.input;
show = show && document.activeElement === this.input;
let clearButton = this.element.querySelector('button');
clearButton.style.visibility = show ? 'visible' : 'hidden';
}