1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    2
    Vote Rating
    0
    orech is on a distinguished road

      0  

    Default Unanswered: ST 2.1 - Custom form validation per field

    Unanswered: ST 2.1 - Custom form validation per field


    Hello,
    I've got 2 forms in my app:
    - Login form (email, password)
    - Registration fom (name, surname, email, password)

    I'm using model for validation:
    Code:
    Ext.define('First.model.User', {    
    extend : 'Ext.data.Model',
        config : {
            fields : [{
                name: 'id',
                type: 'integer'
            },
            {
                name: 'name',
                type: 'string'
            },
            {
                name: 'surname',
                type: 'string'
            },
            {
                name : 'email',
                type : 'string'
            }, {
                name : 'password',
                type : 'password'
            }],
            
            validations : [{
                type : 'presence',
                name : 'name',
                message : 'Enter name'
            },{
                type : 'presence',
                name : 'surname',
                message : 'Enter surname'
            },{
                type : 'presence',
                name : 'email',
                message : "Enter email"
            }, {
                type : 'presence',
                name : 'password',
                message : "Enter Password"
            }, {
                type : 'format',
                name : 'email',
                matcher : /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/,
                message : 'Email format is invalid'
            }]
        }
    });
    After submitting Login form I get an error concerning field that are not in the form (name, surname). Is it possible to rewrite presence rule so it won't be applied when there is no such field? Presence rule should be disabled in Login form, but not in Registration form.

    I've tried to make custom presence rule in Login form controller, but I've got no idea how to check field presence in form.

    Thanks for help in advance

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,677
    Answers
    3355
    Vote Rating
    749
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    No but you can choose to ignore the error you get back depending on how you are submitting and handling it. Not really a presence validation if you don't require the presence.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    2
    Vote Rating
    0
    orech is on a distinguished road

      0  

    Default


    Application listens confirm button and after tapping it validates and submit the form (or shows errors). Handler for this action is placed in Controller. This is the handler:

    Code:
    // Checks form and log in    
    btn_confirmLogin : function() {
            
            var me = this;
            
            var model = Ext.ModelMgr.create(me.getForm_loginForm().getValues(), 'First.model.User');
    
            // Validate
            var errors = model.validate();
            var message = '';
    
            if (errors.isValid()) {
                // Validation successful - show loader
                Ext.Viewport.setMasked({
                    xtype : 'loadmask',
                    message : 'Logging in...'
                });
                // Login
                me.getForm_loginForm().submit({
                    url : 'http://localhost/first/?do=login',
                    method : 'POST',
                    success : function(form, result) {
                        // Save user
                        var user = Ext.create('First.model.User', {
                            id : result.user.id,
                            name : result.user.sFirstname,
                            surname : result.user.sLastname,
                            email : result.user.sEmail
                        });
    
                        // Save user to store
                        var users = Ext.create('First.store.Users');
                        // var users = Ext.getStore('usersStore');
                        users.add(user);
    
                        // Loader off
                        Ext.Viewport.setMasked(false);
    
                        // Move to homepage
                        me.push(me.getNvw_main(), 'First.view.HomePage');
                    },
                    failure : function(form, result) {
                        // Loader off
                        Ext.Viewport.setMasked(false);
                        
                        Ext.Msg.alert("Login Failed", result.error);
                    }
                });
    
            } else {
                // Validation failed
                var data = "";
                errors.each(function(item, index, length) {
                    data += item.getMessage() + '<br />';
                });
                Ext.Msg.alert("Validation Failed", data);
    
                return false;
            }
        }

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar