What is the type of availability check?

What is a check presence?

validations: [{
            type: 'presence',  
            field: 'age'
            }]  

Please help with a good example.

+4
source share
1 answer

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'
});

// 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
});
+5
source

All Articles