Search code examples
validationextjstouch

Validations in Sencha Touch Architect


I am very new to sencha touch, and i am using Architect. I have a controller "RegisterUser"(controlleractiontap) which has a function.. when i fill in some user data and I click register button in my formview it will write the user to my local database.

I have a model called "userModel" which contains the following:

fields: [
        {
            name: 'Username',
            type: 'string'
        },
        {
            name: 'Password',
            type: 'string'
        },
        {
            name: 'Firstname',
            type: 'string'
        },
        {
            name: 'Lastname',
            type: 'string'
        },
        {
            name: 'Phonenumber',
            type: 'string'
        },
        {
            name: 'Email',
            type: 'string'
        }
    ],
    validations: [
        {
            type: 'presence',
            field: 'Username'
        },
        {
            type: 'email',
            field: 'Email'
        },
        {
            type: 'length',
            field: 'PhoneNumber',
            max: 10,
            min: 10
        }

the problem: how do i call my validators in the controller so it will validate the fields in my form?

if i missing some information to make it more clear just let me now.

Thanks in advance!


Solution

  •   var val=Ext.create('talkbag.model.Registration',new Ext.getCmp("registration").getValues());
    

    where "registration" is the id assigned to the view that extends Ext.form.Panel

    var check=val.validate();
    

    now you can check like this if (!check.isValid())