What is presence
type validation?
validations: [{
type: 'presence',
field: 'age'
}]
Please help for illustrative example.
What is presence
type validation?
validations: [{
type: 'presence',
field: 'age'
}]
Please help for illustrative example.
According to documentation,It simply ensures that the field has a value.
First define a Employee model like 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 Employee model previously created. Note that we are not assigning value to name field,which has presence validation.
var newEmployee = Ext.create('App.model.Employee', {
id: 1,
salary: 5555.00,
address: 'Noida'
});
// Validating a model.
var errors = newEmployee.validate();
//Now print the error message
errors.each(function (item, index, length) {
console.log('Field "' + item.getField() + '" ' + item.getMessage());//Field "name" must be present
});