PDA

View Full Version : Model date versus Form date - different formats don't work?



daniel123
19 May 2012, 6:01 AM
hello,

I have a bit of an issue with getting a date from my datefield/datepicker (format: 'd-M-Y') into my model (Y/d/m H:i:u).

I have a screen with a list and edit part. The list is connected with a store holding models with a date field in format (Y/d/m H:i:u). a grid show the models. The grid displays the date as 'd-M-Y'
When i click a grid-line in the list a form.panel is filled with the selected model:
form.loadRecord(grid.getSelectionModel().getSelection()[0])
the date field on the form has also format of 'd-M-Y'.

Untill know everything is smelling like roses.....

WHen i want to save the edited fields i do:
model.set(form.getValues()), where model is the selected line in the grid and form is the form with the formfields. Via store.sync the changed information is written to the backend.

Now it starts to smell......

I have tried and looked into the doc but cannot find a way how to get the parsed value of the date from the form.
The date is not the date field but the text representation. I would like to get the underlying actual date.
The date field of the form is: Ext.form.field. So somewhere the date should be there no?
Currenlty the set(form.getValues) will result in null values sent to the server, since the format doesn't match the model format. It would be nice to have the altFormat on the model as well, this then can solve the issue.

What i like very much is the model.set; it saves me from iterating the form fields to the model.
However, I would like to set the actual fields rather then the simpel text representations that are on the form.

If anyone knows how to get the Date rather then the textstring input field, it would be much appreciated.

vietits
19 May 2012, 3:29 PM
Let have a try by setting submitFormat of form date field to 'Y/d/m H:i:u' or using <form>.getFieldValues() instead of <form>.getValues().

daniel123
21 May 2012, 3:37 AM
Thanks for the comment.

The submit date did the trick, but still had problems sending the date.
The model seems to change the json send.
It now was formatted as 2012-01-01T0:00:00 in the send request.

I changed the json:
Ext.JSON.encodeDate = function(d) { return Ext.Date.format(d, '"Y/m/d H:i:s"');
}

This does the trick.

Regards and thanks