ValidateCollection¶
-
class
webix.
ValidateCollection
()¶ Validatecollection mixin
Referenced by¶
- mixins
Touch()
.- components
DataCollection()
.- views
proto()
.
External references¶
Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | webix.ValidateCollection = {
_validate_init_once:function(){
this.data.attachEvent("onStoreUpdated",webix.bind(function(id, data, mode){
if (id && (mode == "add" || mode == "update"))
this.validate(id);
}, this));
this.data.attachEvent("onClearAll",webix.bind(this.clearValidation, this));
this._validate_init_once = function(){};
},
rules_setter:function(value){
if (value){
this._validate_init_once();
}
return value;
},
clearValidation:function(){
this.data.clearMark("webix_invalid", true);
},
validate:function(id){
var result = true;
if (!id)
for (var key in this.data.pull)
var result = this.validate(key) && result;
else {
this._validate_details = {};
var obj = this.getItem(id);
result = webix.ValidateData.validate.call(this, null, obj);
if (result){
if (this.callEvent("onValidationSuccess",[id, obj]))
this._clear_invalid(id);
} else {
if (this.callEvent("onValidationError",[id, obj, this._validate_details]))
this._mark_invalid(id, this._validate_details);
}
}
return result;
},
_validate:function(rule, data, obj, key){
if (typeof rule == "string")
rule = webix.rules[rule];
var res = rule.call(this, data, obj, key);
if (!res){
this._validate_details[key] = true;
}
return res;
},
_clear_invalid:function(id){
this.data.removeMark(id, "webix_invalid", true);
},
_mark_invalid:function(id, details){
this.data.addMark(id, "webix_invalid", true);
}
};
|