Results 1 to 2 of 2

Thread: Datepicker/datepickerfield does not allow setting null values

    You found a bug! We've classified it as TOUCH-4591 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha User
    Join Date
    Apr 2013
    Vote Rating

    Default Datepicker/datepickerfield does not allow setting null values

    The title is a little misleading, because you can *set* the datepicker to a null value. It will just never return that null value back.

    Use Case

    Say you have an optional date field on a form; users should be able to set the date, and then hit a 'clear' button to remove the date.

    Expected Behavior

    In code, I should be able to set the datepickerfield to null; the text field component should then be blank. Then when I getValue() on the field, I should get null.

    Actual Behavior

    Setting the datepickerfield to `null` appears to work fine; the text field is set to an empty string. But when you call getValue on the field (or call getValues on the form), you get whatever the datepicker was set to previously.

    The Bug Is Here

    The setValue function in Ext.picker.Date calls callParent, calling setValue on Ext.picker.Picker. This function handles setting the value to a null just fine; because the picker is actually an array of values, it sets each of them to null. Here's that relevant code:

            if (!values) {
                values = {};
                for (i = 0; i < ln; i++) {
                    //set the value to false so the slot will return null when getValue is called
                    values[slots[i]] = null;
    And then later it sets:

            me._values = me._value = values;

    Ok, setValue appears to work. BUT: the getValue function in Ext.picker.Date actually queries each picker-slot for its value; it ignores the me._values that we saw was set in setValue(). And since picker-slots can't be null, it just returns whatever the picker was set to before we did a .setValue(null).

    Possible Fix

    I've worked around this in Ext.picker.Date#getValue by first checking to see if this._value is set and null; if it's null, I just return null without querying the slots.

    Here's the extended Ext.picker.Date I'm using:
      Ext.define("Ext.better.picker.Date", {
        extend: "Ext.picker.Date",
        getValue: function(useDom) {
          if (this._value && === null && !useDom) {
            return null;
          return this.callParent([useDom]);
    This is of course a pain in the ass to implement, since I have to hack into the datepickerfield as well, to tell it to use this date-picker component instead of the stock one.

    Would be great to fix this to allow the datepicker to not only be set to null, but to also return null.

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Thanks for the report! I have opened a bug in our bug tracker.

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