Validation in dynamically generated forms in Extjs

I’m developing the eforms framework, there will be many products available, and each product will have different shapes. When you drag it, it will appear in the form panel, the form data of the panel will be deleted from the Json file. We have a json file for each form. If I want to add checks to these fields in forms, this means that I can do this, the fields of the bcoz form are available in json, which will be dynamically generated when drag and drop.

Can the guys help me with this.

thank you and welcome rajNaveen

+3
source share
1 answer

Do you associate a model with forms? If so, you can introduce validation logic into the model. For instance:

Ext.define('MyModel', {
    extend: 'Ext.data.Model',
    fields: ['field1', 'field2'],
    validations: [
         { type: 'presence', field: 'field1' }
    ]
});

: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.validations

, . ( MVC):

onFormSave(): function() {
    var form = this.form.getForm(),
        updatedRecord = MyModel.create();
    form.updateRecord(updatedRecord); //saved all the data from the form, to empty object
    var errors = updatedRecord.validate(); //validate the object
    if (errors.isValid()) { //if the object is valid, then save the data to the model associated with the form.
        form.updateRecord(form.getRecord());
    }
    else {
         form.markInvalid(errors);
    }
}

, . , , , , .

+2

All Articles