Login Register

Date Obj Problem: IE7:Wed May 7 00:00:00 UTC+0200 2008 / FF2:Wed May 07 2008 00:00:00 GMT+0200 (CEST) ???

Hi there,

I'm getting bugged for a long time and haven't found a solution yet :(

When I use datetextbox, the value is getting submitted
in FF2:Wed May 07 2008 00:00:00 GMT+0200 (CEST).

That works great.

But in IE7 the date-style differs from FF2:
Wed May 7 00:00:00 UTC+0200 2008

Following my PHP-backend is not able to "read" and convert the
date-string from IE7.

I read all threads here I found, but I did not know
how to solve this problem :(

my dojo-config is

djConfig = {
parseOnLoad: true,
isDebug: false,
debugAtAllCosts: true,
useXDomain: true,
dojoBlankHtmlUrl: '/blank.html',
preventBackButtonFix: false,
dojoIframeHistoryUrl:'/iframe_history.html',
extraLocale: ['de-de', 'en-us'],
usePlainJson: true
};

my dijit look like

(input
id='test'
name='test'
tabindex=1
class=''
value='$dojoDateStringValue'
dojoType='dijit.form.DateTextBox'
required='true'
)";

thx for help!!
melchior

IIRC, what you are getting from IE7 is...

...actually the correct notation; date values should be (as a best practice) in UTC, and not GMT (even though they represent the same basic idea).

Probably what you'll want to do is connect to the parse method of the widget, and change the parsed value by explicitly converting to UTC using the Date.toUTC...methods. This is straight up JS, lots of resources to use.

The other method would be to use a regular expression or the like just before submitting the value, something like:

var value=value.replace("UTC", "GMT");

It's a pretty cheesy hack but it should work just fine.

totaly confused

hi ttrenka,

thx for your reply.

I'm totaly confused.

If I compare both:

from IE7: Wed May 7 00:00:00 UTC+0200 2008
from FF2: Wed May 07 2008 00:00:00 GMT+0200 (CEST)

it's not only the "UTC"/"GMT" that differs.
the year-postion has another format.

is that right so?
I didn't found any way to convert the IE7-date-format to timestamp in php.
I always get a negative number..

thx for help
melchior

hrm, didn't notice that one.

Think you're going to have to manually assemble your date out of a data object, probably the easiest way to do it is use dojo.date.locale.format:

http://api.dojotoolkit.org/jsdoc/dojo/HEAD/dojo.date.locale.format

I was looking at the differences with the timezone, which includes your Central Europe Standard Time.

Either way, you should be able to get what you need using dojo.date.locale.format.

overriding serialize method won't work :(

hi,
I just started to test overriding the serialize method from
the dateTextBox-dijit.

but it didn't take any effect to me :(

I tested:

    dojo.declare
          ("myDateTextBox",[dijit.form.DateTextBox], {
                  serialize: function(d, options) {
                     return dojo.date.locale.format(
                         d, {selector:'date', datePattern:'dd-MMM-yyyy'}).toLowerCase();
                   }
               }
           );

The inheritance is working well - the dijit gets displayed by calling <input dojoType='myDateTextBox' ...>
but when I submit the wrapping dijitForm the result returns the "old ISO-formated-date" like before :(

big thx for help!
melchior

serialize only executed after dijit-onload

hi,

I found out that "serialize" gets executed only at dijit-onload. And not
while submitting my encapsulating dijit-form.

"
If I trigger serialize by dijit.byId('datetest').serialize() the arguments
of
.. ("myDateTextBox",[dijit.form.DateTextBox], {
serialize: function(d, options) {

--> d and options are always null.

(when triggered after the dijit has been loaded, the arguments are always fine)

I think I got a deeper bug that could explain why I never got
a "normalized" date output to server yet.

I' ve got no idea whats going wrong.
I searched the dojo-website for a long time without success :(

any ideas?
melchior

The stuff in DateTextBox is admittedly complex.

http://api.dojotoolkit.org/jsdoc/dijit/HEAD/dijit.form._DateTimeTextBox....

Take a look at that. The .getValue() method of the widget (IIRC what is called by the form submitter) gets it's value from this method; if you use a constraints object, you might get more of what you are looking for. You can look at the test in the nightlies to see how to define a constraints object:

http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/form/test...

Try that out and see if that does the job for you. I know that you can define formatting options with it but not exactly what options are there (I don't do a huge amount of in-depth Dijit dev, I'm more on the other side of things).

should work by default

it shouldn't be complex at all, at least in the common case. We deliberately designed DateTextBox not to localize results to the server. Overriding serialize() should not be necessary.

If you process your form normally and look for the named property 'test' in the submitted form data, what you should see on the server, regardless of browser, is something like

2008-05-07T00:00:00Z

If that's not what you're seeing, we might need a complete test case to see what's going on.

testcase available

hi,

I stripped down a test-case that demonstrates the problem.
I've never had a formated string :(

I've always had
IE7: Wed May 7 00:00:00 UTC+0200 2008
and FF2: Wed May 07 2008 00:00:00 GMT+0200 (CEST)

Here you can see a "live-demo".

You can choice how to get the date-data between per formDijit or dijit.serialize().
Note: The return value needs Firebug to be visible

besides I made an offline-version with 1 page only.
Just download the zip-file, extract and copy dojo into the dir "dojo_1_1".
Open testcase.html. Thats all.
download

would be really nice to get this solved :)

thx!
melchior

sorry for pushing

sorry for pushing

I'm really desperate :(

The project that make use of this code has been launched yet
and I've to fix this problem as fast as possible.

I cannot see any error in my code.
It's very lightweight so there aren't any critical points, afaik.

I'm thinking about to fix this 'quick and dirty' by reconstructing
the wrong-formated posted time-data by an regular-expression-pattern.

but this isn't a real solution
and I don't have much regex-skills :(

regards and thx,
melchior

ok, so your code is dealing with Javascript Date objects

Please take a closer look at the 'values' variable that you're passing to console.dir. values.deadline, the value of the widget as accessed by Javascript, is a "Date" object. If you simply print values.deadline to the console, it's doing an implicit toString() on a Date. Browsers don't do this in a consistent way. This is why by default, our dijit.DateTextBox will make use of our dojo.date.stamp module to submit the value in ISO-8601 format. If you simply let the form submit do its thing, you should see something like "2008-05-09" associated with the form element named 'deadline', e.g. deadline=2008-05-09 There are tests in dijit/tests/form which demonstrate this.

Now, once you write custom JS code to extract values from your form elements using getValues() and submit them, you're dealing with Javascript Date objects. If you wish to interact with the values on the client or do calculations with them locally, Date objects are a very convenient format. However, any time you wish to send a Date object to the server, you should call dojo.date.stamp.toISOString() to get a canonical representation. Do not simply let the browser's Date.toString() coerce the Date object to a string, or you'll get results like the ones you're seeing. This is true of all JS, not just Dojo.

Hope this makes some sense. btw, you should not need to mess with the extraLocales method or override serialize. The default should get you a portable, safe result in the form YYYY-MM-DD

p.s. how do we improve our docs?

once you get your head around this, please feel free to give us feedback on how we can more effectively get this message out. We try to encapsulate as much of this behavior in the widget as possible, and I've tried to put inline docs for all of this code. Perhaps there's a better way to explain this?

catchin by node.value works, but is it good/best practice?

puuhh thxx,
now I got the iso-formated date :)

I catched it with:

formData=formDijit.getValues();

dojo.query('input[name*="date_"]', formID).forEach(function(node){
formData[node.name] = node.value;
});

so all form-fields beginning with "date_" like "date_deadline" are
getting catched by node.value instead of using the value grabbed by dijit-form.

If this is the only way to get a normalized iso-date while using dijit-form to
get values of a textbox I would propose to enhance this handling by fixing
the form-dijit. At least a highlighted note at docs would be essential to don't
fall in this trap by relying in smart-dijit-usage like me.

If I'm still wrong or/and overlooked sth. please give me a notice :)

I'm really a big fan of dojo and always motivated
to enhance my skills of it.

thx and regards,
melchior

no... use date.getValue()

we can't control the value property all the time, which is why we have the get/set accessors. I don't think 'value' is guaranteed to be up to date. Also, note that there will be two inputs for each DateTextBox... I forget how we named the shadow one.