extjs - Validation data in Ext.Model -
help me please. models have built-in support validations, executed against validator functions in ext.data.validations. code:
ext.define('user', { extend: 'ext.data.model', fields: [{ name: 'name', type: 'string' },{ name: 'age', type: 'int' },{ name: 'phone', type: 'string' },{ name: 'gender', type: 'string' },{ name: 'username', type: 'string' }], validations: [ { type: 'length', field: 'name', min: 2 },{ type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/ }] }); var person = ext.create('user', { name: 'eugene', username: 'popov', gender: 'f', age: 300, married: false }); console.log(person.get('name')) person.set('name','u'); console.log(person.get('name'))//u });
i've read model can filter data . principle of work? why can write wrong values in example? thanks!
model validations don't reject changes themselves. editing model through other component (like stores or grid editors) may provide feature. validations come play when calling validate
or isvalid
methods on model.
if models part of store, can listen store's update
event (link docs). within event handler, can validate model , reject changes want.
// simple demonstration store.on('update', function (store, model, operation) { if (operation === ext.data.model.edit && !model.isvalid()) { model.reject(); } });
Comments
Post a Comment