I am creating a model for a form which needs some validations.
The model looks like this:
//Defining a data structure for the Work Item List
Ext.define('InfoImage.model.configure.configModel', {
extend : 'Ext.data.Model',
config : {
//Defining the fields required in the Work Item List
fields : [ 'servname', 'port', 'protocol', 'username', 'password',
'domain', 'appconfig', 'apptitle',
'appconfig' ],
validations : [
{
type : 'presence',
name : 'servname'
},
{
type : 'presence',
name : 'port'
// matcher : /[0-9]{4}[A-Z]+/
},
{
type : 'presence',
name : 'username'
},
{
type : 'presence',
name : 'password'
}],
proxy : {
type : 'localstorage',
id : 'configId'
}
}
});
I tried calling the validation by
Ext.getCmp('form').validate();
but it says that it has no method called validation.
Does sencha provide a method for validation? If yes, how can i achieve it?
Sencha does indeed provide a method for validating models. Have a read through the docs: http://docs.sencha.com/touch/2-0/#!/guide/models-section-3
I guess you can use form.getValues() to populate a new model, and then use the validate() method on the model to validate the data.