According to the documentation, It simply ensures that the field has a value.
First define the Employee model as shown below.
Ext.define('App.model.Employee', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'salary', type: 'float' },
{ name: 'address', type: 'string' },
],
validations: [
{ type: 'presence', field: 'name' }
]
}
});
Now create an instance of the previously created Employee model. Please note that we do not assign a value to a name field that has a confirmation of presence.
var newEmployee = Ext.create('App.model.Employee', {
id: 1,
salary: 5555.00,
address: 'Noida'
});
var errors = newEmployee.validate();
errors.each(function (item, index, length) {
console.log('Field "' + item.getField() + '" ' + item.getMessage());
});
source
share