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
    Posts
    10
    Vote Rating
    0
    frayjusto is on a distinguished road

      0  

    Default Datepicker/datepickerfield does not allow setting null values

    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:

    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].config.name] = null;
                }
            }
    And then later it sets:

    Code:
            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:
    Code:
      Ext.define("Ext.better.picker.Date", {
        extend: "Ext.picker.Date",
        getValue: function(useDom) {
          if (this._value && this._value.day === 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    850
    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


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

Thread Participants: 1

Tags for this Thread