Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#8050 closed defect (wontfix)

Date time box needs a new prototypal function to retrieve date values.

Reported by: spidey2099 Owned by:
Priority: high Milestone: tbd
Component: Dijit Version: 1.2.0
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

Context: added a DateTimeBox to a Form programmatically. The first issue was the the date value was not showing up. Luckily the test indicated this methodology which varies from the inline code. (inline DateTextBox.value = "2008-11-09" programmatic code DateTextBox.value = new Date ("2008-11-09").

The second issue is that when the values were extracted from the form, the date's value was empty. This is what had to be done to view the date's value.

  function getValues (arguments) {
      Date.prototype.json = function(){
         return dojo.date.stamp.toISOString(this, obj.Date.value);
       };

       var obj = dijit.byId("0").attr('value');
       alert("Object is: " + dojo.toJson(obj, true));
   }

Thankfully the Date.prototype.json code snippet was in the tests as well. However - shouldn't this function be part of the Date object? Users shouldn't have to read the tests to determine how a Date function should be extended in order to find the value of a date.

Admittedly a Date construct is a bear and the way dojo has implemented it is very nice. However, if we could have this functionality as part of the Date function that would be very helpful.

Change History (3)

comment:1 Changed 11 years ago by bill

Description: modified (diff)
Resolution: wontfix
Status: newclosed

Hi Spidey,

inline DateTextBox.value = "2008-11-09" programmatic code DateTextBox.value = new Date ("2008-11-09")

This issue has caused confusion before but it's by design. In markup all parameters are specified as strings and the parser does type conversion. However, when creating widgets programatically the user must pass in the right types for parameters. The value parameter is a Date object, as listed in http://api.dojotoolkit.org/jsdoc/dijit/1.2/dijit.form.DateTextBox.

As for the Date.prototype.json thing, that's really an issue with dojo.toJson(), not with the widget. Note that attr('value') for DateTextBox returns a Date object and works correctly w/out the Date.prototype.json hack.

However - shouldn't this function be part of the Date object?

By policy dojo doesn't modify native javascript "classes" like Array or Date, because we don't want to do something that interferes w/other toolkits / affects code outside of dojo. Perhaps dojo.toJson() should be enhanced to have a registry of types and serializers for them. Of course, that won't solve problems with dojo.fromJson(), which doesn't know which fields are supposed to be dates.

Anyway, the idea of a registry is covered in other ticket(s).

comment:2 Changed 11 years ago by spidey2099

Bill,

Yes - the problem wasn't with the widget. However I read and experimented as much as I could prior to coming upon the hacked solution. (For instance, among other things, I did try dijit.byId (DateTimeBox?.id).value which resulted in null). Is the right methodology for the DateTimeBox? documented somewhere just in case I missed it? I ask because most other widgets in a Form (for instance) express their values without special attention. But the Date object comes up empty if it is retrieved without individual processing for the DateTimeBox? widget. Knowing the right thing to do could be helpful to us when doing Form generation and processing.

I think that the change to dojo.toJson which you have outlined would be very helpful.

Thanks for the info,

John

comment:3 Changed 11 years ago by bill

FYI, #6924 also addresses this issue with DateTextBox, but if you wanted functionality in dojo.toJson() as I mentioned above you could file another ticket.

Note: See TracTickets for help on using tickets.