1. #1
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,668
    Vote Rating
    746
    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 Date Range Model validation

    Date Range Model validation


    I had a requirement to check if a start date was truly before an end date while using a pair of datefields. Instead of creating a VType or a validator for them, I wanted to use the validations on the Ext.data.Model class. Had to create two overrides to do this, one for Ext.data.Model and one for Ext.data.validations:

    Code:
    Ext.require('Ext.data.validations', function() {
        Ext.apply(Ext.data.validations, {
    
            daterangeMessage : 'Start date must be before the end date',
    
            daterange        : function(config, value, record) {
                var minValue = record.get(config.minField),
                    maxValue = record.get(config.maxField);
    
                return minValue < maxValue;
            }
        });
    });
    
    Ext.require('Ext.data.Model', function() {
        Ext.data.Model.override({
    
            validate: function() {
                var errors      = Ext.create('Ext.data.Errors'),
                    validations = this.validations,
                    validators  = Ext.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), this); // added 3rd argument to pass model instance
    
                        if (!valid) {
                            errors.add({
                                field  : field,
                                message: validation.message || validators[type + 'Message']
                            });
                        }
                    }
                }
    
                return errors;
            }
        });
    });
    First one is the actual validation method and message. The second is to the validate method on the Ext.data.Model class. In 4.0.7, you can only do single field validations because it doesn't pass the Model instance to the validation method. Highlighted in red is the change to accomplish this, nothing special.

    Here is the example:

    Code:
    Ext.define('DateModel', {
        extend : 'Ext.data.Model',
    
        fields : [
            { name : 'start', type : 'date' },
            { name : 'end',   type : 'date' }
        ],
    
        validations : [
            { type : 'daterange', name : 'daterange', minField : 'start', maxField : 'end' }
        ]
    });
    
    var model = Ext.create('DateModel', {
        start : new Date(),
        end   : Ext.Date.add(new Date(), Ext.Date.DAY, -1)
    });
    
    var errors = model.validate();
    This should return the errors mixedcollection with an error.
    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.

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    srossshell is on a distinguished road

      0  

    Default Is it possible to create a custom daterangeMessage

    Is it possible to create a custom daterangeMessage


    Say for example, you have a single date field and that field can be any value between 1st march and the 1st June 2013

    So your daterangeMessage would be "The date must be between 1st Mar 2013 and the 1st Jun 2013?

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    srossshell is on a distinguished road

      0  

    Default


    When I said custom, i meant dynamic. So that the message would be generated from the start and end values set on the Model.

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    srossshell is on a distinguished road

      0  

    Default I think I found my answer

    I think I found my answer


    For anyone else

    http://oajamfibia.wordpress.com/2011...ons-in-extsj4/

Thread Participants: 1

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