Skip to content Skip to sidebar Skip to footer

Extjs Form.field.date Recalculates Date If Non-valid Mm Or Dd Is Entered. How To Prevent?

The default ExtJS form.field.date allows manual entry/editing of a date in addition to using the datepicker. However, if you enter a number larger than 31 for the DD or larger than

Solution 1:

There isn't a config option that allows you to do that.. but what you can do is provide a validator function. This function get's called before the default validation, which i assume must be changing the values' takes place.

newExt.form.DateField({

   validator : function(value){
      var split = value.split('/'); //Assuming / is your seperatorif(split[0] > 31)
      {
        //Show error 
      }
      // Other validations etc.
   }
});

If the value changing takes place before the validator gets called, then add config option: validateOnBlur : true

Solution 2:

Adding an answer to my own question found via the ext forum post.

What Ext calls the date "rollover" functionality can be turned off by adding useStrict: true. See the documentation.

I wanted to remove the rollover functionality site-wide, so I added this to our main Ext util.js that is used throughout the site:

Date.useStrict = true;

As I mentioned in the ext forum, I can't image why this rollover behavior would be useful to a front-end user -- why would someone want to intentionally enter, say, 01/33/2011 and intend to have it result in 02/02/2011.

Post a Comment for "Extjs Form.field.date Recalculates Date If Non-valid Mm Or Dd Is Entered. How To Prevent?"