Results 1 to 3 of 3

Thread: Record not passed to validator

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-18997 in 6.0.2.
  1. #1
    Sencha Premium Member
    Join Date
    Nov 2007
    Location
    Sydney
    Posts
    116
    Vote Rating
    20
      0  

    Default Record not passed to validator

    The docs suggest that the value and record are passed to the validate function of a vaildator, however in 6.0.1, only the value is passed in.

    http://docs.sencha.com/extjs/6.0/6.0...ethod-validate

    I'm trying to build a custom validator to compare two fields in a model are equal. I'm doing the validation at the model level as this is for a universal app.

    The code for my validator is straight forward, but record is null causing it not to work:

    Code:
    Ext.define('App.ux.data.validator.EqualField', {
        extend: 'Ext.data.validator.Validator',
        alias: 'data.validator.equalfield',
        
        type: 'equalfield',
        
        config: {
        	fieldName: null
        },
        
        validate: function(value, record) {
            var result = (value === record.get(this.getFieldName()).getValue());
            return result || this.getMessage();
        }
    });

  2. #2
    Sencha - Support Team bjdurham85's Avatar
    Join Date
    Mar 2014
    Posts
    962
    Vote Rating
    21
      0  

    Default

    Hi CaCtus491,


    Thanks for the report, this has been fixed and will available in a future release.


    Regards,
    Bryan

  3. #3
    Roberto Lopez's Avatar
    Join Date
    Feb 2016
    Location
    Dallas Texas USA
    Posts
    23
    Vote Rating
    0
      0  

    Default

    Here is the override to solve this issue.

    Code:
    Ext.define('Vantage.override.app.bind.Stub', {
        override: 'Ext.app.bind.Stub',
    
    
        bindValidationField: function (callback, scope) {
            //debugger;
            var parent = this.parent,
                name = this.name,
                lateBound = typeof callback === 'string',
                ret;
            if (parent) {
                ret = parent.bind(function (value) {
                    var field = null;
                    if (value && value.isModel) {
                        field = value.getField(name);
                    }
                    if (lateBound) {
                        //scope[callback](field, null, this);
                        scope[callback](field, value, this);
                    } else {
                        //callback.call(scope, field, null, this);
                        callback.call(scope, field, value, this);
                    }
                });
            }
            return ret || null;
        }
    });

Similar Threads

  1. Replies: 5
    Last Post: 31 Dec 2018, 10:54 AM
  2. Replies: 0
    Last Post: 8 Sep 2015, 9:11 AM
  3. Replies: 3
    Last Post: 19 May 2014, 4:30 AM
  4. Replies: 1
    Last Post: 27 Jul 2011, 5:43 PM
  5. record passed in getDetailCard - where am I going wrong?
    By irocker in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 19 Feb 2011, 10:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •