Reputation: 10802
I have a form with several fields. One of those fields has xtype of datefield. Values for this form come from a json file, which looks like so:
{"field_1":"text value", "field_2": "2017-08-16T21:00:00.000Z"}
However, when I do:
form.setValues(json);
only the first field is set. The second datefield, which is defined like:
{
"xtype":"datefield",
"name": "field_2"
}
is not set for some reason. What is wrong with that and how can I fix it?
Upvotes: 0
Views: 220
Reputation: 20224
Because JSON does not support javascript dates natively, the value in field_2 is a string, not a javascript date.
While a string can represent a date, there are a variety of formats. In this case the string is in a format unrecognized by datefield. When the datefield tries to set the value, it will try to parse the string into a date, but since your selected format is not one known to datefield by default, the value is set to null.
The format
and altFormats
configs contain the formats datefield recognizes, and can be exchanged/amended to contain the date format(s) you want to support.
Upvotes: 2