# How Ext JS form validations work?

**URL:** <https://forum.shopware.com/t/how-ext-js-form-validations-work/34209>\
**Category:** Programmierung\
**Created:** [4. Februar 2016 um 10:02 UTC](https://forum.shopware.com/t/how-ext-js-form-validations-work/34209 "2016-02-04T10:02:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cboita](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cboita](https://forum.shopware.com/u/cboita)\
**Post date:** [4. Februar 2016 um 10:02 UTC](https://forum.shopware.com/t/how-ext-js-form-validations-work/34209/1 "2016-02-04T10:02:20Z")

</div>

```
 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](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

---

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [4. Februar 2016 um 13:26 UTC](https://forum.shopware.com/t/how-ext-js-form-validations-work/34209/2 "2016-02-04T13:26:30Z")

</div>

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.
