How Ext JS form validations work?

 Hi there

I’m developing a backend plugin and I’m trying to understand how to apply valitations to my form. I checked out the Ext JS documentation for model definition :http://www.objis.com/formationextjs/lib/extjs-4.0.0/docs/api/Ext.data.Model.html

Based on that my model/sales_representative.js looks like:

Ext.define('Shopware.apps.SalesRepresentative.model.SalesRepresentative', {
    extend: 'Shopware.data.Model',

    configure: function() {
        return {
            controller: 'SalesRepresentative',
            detail: 'Shopware.apps.SalesRepresentative.view.detail.SalesRepresentative'
        };
    },

    fields: [
        { name : 'id', type: 'int', useNull: true},
        { name : 'firstName', type: 'string' },
        { name : 'lastName', type: 'string' },
        { name : 'email', type: 'string' },
        { name : 'salutation', type: 'string', useNull: true },
        { name : 'image', type: 'string', useNull: true },
        { name : 'assignable', type: 'boolean' }
    ],

    validations: [
        { field: 'firstName', type: 'length', min: 1},
        { field: 'lastName', type: 'length', min: 1},
        { field: 'email', type: 'presence'},
        { field: 'email', type: 'format', matcher:/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
            message:'{s name=valitation_email_format}Wrong Email Format{/s}'}
    ]

});

If I try to save my form, validations don’t work and I can save independently I have firstName filled or a wrong email format.

Then I was searching aroung Shopware code and I saw that on Backend/ExtJs/backend/customer/view/detail/base.js the fields are created from scratch there on

 createBaseForm function.

So the question is, what is the best/easy approach to apply validations to our forms? Is it possible without have to create form fields from scratch?

Thanks

hi,

take a look at:

/themes/Backend/ExtJs/backend/form/model/field.js

/themes/Backend/ExtJs/backend/form/view/main/fieldgrid.js

/themes/Backend/ExtJs/backend/form/controller/fields.js [onValidateEditField() line: 274]

mybe it could help you.