1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    7
    Vote Rating
    1
    karencc is on a distinguished road

      0  

    Default Form field validation based on model validation in sencha touch 2

    Form field validation based on model validation in sencha touch 2


    I need to have validation of textfield contents on blur,

    I have already created custom validations for my model fields, is there a way in sencha touch to reuse these validations defined on the model for field validation?

    Also ExtJS seems to have functionality for validation on blur of field etc will this functionality be added in Sencha touch?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,795
    Vote Rating
    834
    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


    If you have a model instance on the form (using setRecord method) then you can easily get the record via getRecord on the form panel and validate it.
    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
    Nov 2011
    Posts
    7
    Vote Rating
    1
    karencc is on a distinguished road

      1  

    Default Form field validation based on model validation in sencha touch 2

    Form field validation based on model validation in sencha touch 2


    Hi Mitchell,


    Thanks for the reply, I follow that you can getRecord and validate it,but I want only the validations particular to the individual form field being changed to be executed. With the validate method of the Model, the validation happens for all the fields defined on the model.Since we have a lot of fields within the model, my concern is that it would affect the application performance.


    This is because on change i need to highlight the field and display the error list for the particular form field.

    Karen

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,795
    Vote Rating
    834
    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


    Then you will need to validate the value manually yourself. You can get validations via

    Code:
    rec.getValidations()
    And that is a MixedCollection which has an each method:

    Code:
    var validators = Ext.data.Validations,
        field, type, valid;
    
    validations.each(function(validation) {
        var field = validation.field || validation.name
        if (field === formfield.name) {
            type = validation.type;
            valid = validators[type](validation, rec.get(field));
    
            if (!valid) {
                //do something here
            }
    
            return;
        }
    });
    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.

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    7
    Vote Rating
    1
    karencc is on a distinguished road

      0  

    Default


    Thanks!

  6. #6
    Sencha Premium Member intellix's Avatar
    Join Date
    Mar 2012
    Location
    UK + Malta
    Posts
    263
    Vote Rating
    18
    intellix will become famous soon enough

      0  

    Default


    How were you able to define your own custom validations? I can't really find any information on how to do this properly.

    I tried something like this, but then it just says no method 'ajax' exists:

    Code:
    Ext.define('Ux.data.Validations', {
        requires: 'Ext.data.Validations'
    }, function() {
        Ext.override(Ext.data.Validations, {
    
    
            config: {
                ajaxMessage: 'is already taken'
            },
    
    
            ajax: function(config, value) {
                return true;
            },
    
    
        });
    });
    I see that Ext.data.Model is hard set to look into Ext.data.Validations to get a list of the possible validation methods... so I tried overriding that to use my overriding one (but then it can't get access to the previous methods like email, length etc)

    Code:
    Ext.define('Ux.data.Model', {
        requires: 'Ext.data.Model'
    }, function() {
        Ext.override(Ext.data.Model, {
    
    
    	validate: function() {
    		var errors      = Ext.create('Ext.data.Errors'),
    			validations = this.getValidations().items,
    			validators  = Ux.data.Validations,
    			length, validation, field, valid, type, i;
    
    
    		if (validations) {
    			length = validations.length;
    
    
    			for (i = 0; i < length; i++) {
    				validation = validations[i];
    				field = validation.field || validation.name;
    				type  = validation.type;
    				valid = validators[type](validation, this.get(field));
    
    
    				if (!valid) {
    					errors.add(Ext.create('Ext.data.Error', {
    						field  : field,
    						message: validation.message || validators.getMessage(type)
    					}));
    				}
    			}
    		}
    
    
    		return errors;
    	},
    
    
        });
    });
    I'm not quite sure to be honest how all this override stuff works and theres nothing in the documentation to really push you along in areas like this :/

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi