Results 1 to 2 of 2

Thread: how to override getErrors validation method for masking value in datefield

  1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    49
    Vote Rating
    0
      0  

    Default how to override getErrors validation method for masking value in datefield

    I have put masking on my datefield using [http://www.sencha.com/forum/showthre...for-Textfield]
    so the getErrors throws an error saying -

    __/__/____ is not a valid date - it must be in the format m/d/Y

    so i want datefield to bypass this but do the validation for allowBlank that is set for the datefieldfield.

    i tried to override getErrors in my ext.define statement as shown below but it does not work.

    Code:
    Ext.define('MyDateField', {
        extend: 'Ext.form.field.Date',
        alias: 'widget.mydatefield',
        allowBlank: false,
        getErrors: function (value) {
            console.log(value);
            var errors = [];
            if (this.value === "__/__/____") {
                errors = [];
            }
            else {
                errors = this.callParent(arguments);
            }
            return errors;
        }
        });
    Basically i want to override getErrors method for the below line in the getErrors method is creating problem as
    Code:
    parseDate("__/__/____")
    is creating error as in below code :

    Code:
    svalue = value;
            value = me.parseDate(value);
            if (!value) {
                errors.push(format(me.invalidText, svalue, Ext.Date.unescapeFormat(me.format)));
                return errors;
            }
    Any kind of help is appreciated.
    Last edited by nil5286; 23 Aug 2012 at 11:54 AM. Reason: more clear question after some investigation about the line causing error

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347
    Vote Rating
    119
      0  

    Default

    Try the fixed code below:
    Code:
    Ext.define('MyDateField', {
        extend: 'Ext.form.field.Date',
        alias: 'widget.mydatefield',
        allowBlank: false,
        getErrors: function (value) {
            console.log(value);
            var errors = [];
    //        if (this.value === "__/__/____") {
            if (value !== "__/__/____") { // check 'value', not 'this.value'
                errors = this.callParent(arguments);
            }
            return errors;
        }
    });

Tags for this Thread

Posting Permissions

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