jii
Version:
Jii - Full-Stack JavaScript Framework
47 lines (38 loc) • 1.13 kB
JavaScript
/**
* @author <a href="http://www.affka.ru">Vladimir Kozhin</a>
* @license MIT
*/
'use strict';
const Jii = require('../BaseJii');
const Validator = require('./Validator');
class BooleanValidator extends Validator {
preInit() {
this.strict = false;
this.falseValue = '0';
this.trueValue = '1';
super.preInit(...arguments);
}
init() {
super.init();
if (this.message === null) {
this.message = ''; // @todo
}
}
validateAttribute(object, attribute) {
var value = object.get(attribute);
if (!this.validateValue(value)) {
this.addError(object, attribute, this.message, {
trueValue: this.trueValue,
falseValue: this.falseValue
});
}
}
validateValue(value) {
if (this.strict) {
return value === this.trueValue || value === this.falseValue;
} else {
return value == this.trueValue || value == this.falseValue;
}
}
}
module.exports = BooleanValidator;