Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#6827 closed defect (fixed)

DateTextBox: onChange() and getValue() strange behavior on blank or invalid value

Reported by: bill Owned by: Douglas Hays
Priority: high Milestone: 1.2
Component: Dijit - Form Version: 1.1.1
Keywords: Cc:
Blocked By: Blocking:

Description

Try the following in test_DateTextBox.html from firebug console:

var w = dijit.byId("q1");
w.setValue(new Date());
dojo.connect(w, "onChange", function(val){ console.log("onChange: ", arguments); });
dijit.byId("q1").setValue(null);
console.log("getValue():",w.getValue());

I see two problems:

  • Upon setValue(null), onChange() is called as onChange(""). DateTextBox.onChange() is usually passed a Date, and thus in this case it should be passed null, since null is the standard way (in C, java etc.) to represent no value for a pointer to an object.
  • getValue() returns undefined. Should return null (since null is the standard way in C, java etc. to represent no value for a pointer to an object).

Neither of these things is likely to impact developers who are surely doing {{if(value)}} or if(!value) in their code, which reponds the same way to null, undefined, and "", but for consistency across the API should use standard values.

Change History (6)

comment:1 Changed 11 years ago by guest

As discussed in the dijit development forum _DateTimeTextBox.getValue/setValue incompatible with Form.getValues/setValues, there is a small but potentially annoying developer impact from getValue returning undefined if the value is not set - if you attempt to use Form.getValues() to get the current state, and then later Form.setValues to restore it, the DateTextBox? value will in fact not be cleared if currently set, because setValue(undefined) seems to be ignored (although setValue(null) would work correctly).

comment:2 Changed 11 years ago by bill

Milestone: 1.2
Owner: set to Douglas Hays
Summary: DateTextBox: onChange() and getValue() strange behavior on empty/invalid valueDateTextBox: onChange() and getValue() strange behavior on blank or invalid value

See also #6922 (filed a separate bug as per comment above).

I talked to Doug about the behavior of DateTextBox. He prefers returning undefined when the DateTextBox is either

  1. blank but required
  2. or invalid (ex: "hello")

and to return "" when the DateTextBox is blank but not required.

However, I'm going to "edict" that DateTextBox.getValue() return null in all these cases. The reason is that it corresponds to the value submitted (if you submit a form containing a DateTextBox that is either blank or gibberish.)

comment:3 Changed 11 years ago by Douglas Hays

Status: newassigned

assuming blank/invalid NumberTextBox? widgets should continue to use NaN instead of changing to null

comment:4 Changed 11 years ago by Douglas Hays

Resolution: fixed
Status: assignedclosed

(In [14346]) Fixes #6827, #6922 !strict. blank values for date/time/number textboxes generate null(NaN for numbertextbox) for getValue/onChange, while gibberish generates undefined so that setValue(undefined) can be used to not modify the existing textbox value, while setValue(null) will blank out the textbox. Added tests to test_validate.html for numbertextbox and to test_datetextbox.html for datetextbox.

comment:5 Changed 11 years ago by bill

The reason setValue(undefined) has no effect is because widgets sometimes do setValue(getValue()) (not sure why or when), and we don't want a DateTextBox with a gibberish value (or a typo) to be blanked out on blur etc.

comment:6 Changed 9 years ago by bill

Component: DijitDijit - Form
Note: See TracTickets for help on using tickets.