DateChooser

Can a format of returned value be changed? Can the control return its value in a regular date format: mm/dd/yyyy?

Yes, set listGrid.dateFormatter to change the default date format for a grid. As covered in the docs, this can be changed system-wide as well.

Am I doing it when I am specifying fields:
…
{name:“DateOfAccident”, title:“Date Of Accident”, type:“date”,
width: 100, endRow: true, colSpan:2, dateFormatter:“toUSShortDate()”},
…

Hi Mark
You don’t need the parenthesis at the end of the formatter name - you are simply specifying a formatter type, not calling a function - so dateFormatter should be set to the string “toUSShortDate” only.
Other than this this should work for you. You can also specify the dateFormatter at the ListGrid level rather than at the field level - whichever is more convenient in your usage.

Not sure what I am doing wrong.
{name:“DateOfAccident”, title:“Date Of Accident”, type:“date”,
width: 100, endRow: true, colSpan:2, dateFormatter:“toUSShortDate”}
I have a test pushbutton with this:
alert(frmGeneral.getField(‘DateOfAccident’).getValue());
It clearly shows avalue that is not “05/15/2007”

Hi Mark,

The SmartClient dateFormatter property controls how the ListGrid displays dates, but the actual value of a field of type:“date” is always a JavaScript Date object, not a String. When you alert() that Date, you are seeing the value of Date.toString(), which differs by browser and locale.

Are you having any trouble using the dateFormatter property to change how dates are displayed in the ListGrid?

Ah, I see.
All I want is to send to my server that date in ‘MM/DD/YYYY’ format.
Also when my form starts the DateChooser has today’s date. Can it be blank?

To have a DateItem that allows null/empty values, set DateItem.useTextField to true (or, within a ListGrid field, set it in editorProperties).

The format SmartClient uses to submit dates is the XML Schema standard. If this won’t work for you, you could either change it in server code or implement dataSource.transformRequest() to change the Date object into a String, formatted however you like, before it is sent to the server.

This is what I am getting on the server Fri May 18 00:00:00 CDT 2007 .
My field is defined like this:
{name:“dateofaccident”, title:“Date Of Accident”, type:“date”, useTextField: true, width: 100, endRow: true, colSpan:2, dateFormatter:“toUSShortDate”},

From the Docs:
… Returns this date in the format: MM/DD/YYYY.

Why do I need to do any custom formatting? What am I missing?

Thanks

Hi Mark,

Have you resolved this yet? If not, and you want more help, please show complete code for how the value is manipulated, how it is saved, and how you are getting the output you showed.

As previously mentioned, SmartClient submits dates in the XML Schema standard, which would look like “2007-05-18”. This has nothing to do with the dateFormatter property, which affects how JavaScript Date objects are displayed, not how they are transmitted to the server.

The value you are showing appears to be the output of a server-side formatter being applied to a server-side Date Object, presumably, sometime after saving has already succeeded.

This is straight from the Request object:
Mon May 14 2007 00:00:00 GMT-0500

At some point I thought I was getting it as “2007-05-18”. Or maybe it was just too much coffee.

“2007-08-15” is the format SmartClient actually sends. Since you haven’t provided any of the requested materials to help you debug further, and you report having seen the correct value after drinking too much coffee, our recommendation is to drink too much coffee again.

I think I am getting “formatted value” instead of raw “mm/dd/yyyy” is because I have:

transformRequest : function (dsRequest) {
        dsRequest.contentType = "application/x-www-form-urlencoded; charset=UTF-8";
        return dsRequest.data;
    },

as a part of my dataSource definition. It was suggested by you because I wasn’t getting any data within Request Object.
what do you think?