PDA

View Full Version : Datefield updates ignored when there is a custom convert method



pgarlaud
12 Feb 2015, 11:04 AM
Here's my use case:

I have a server which returns date on the "YYYY-MM-DD" format, including the "0001-01-01" value when a field is empty.
I want to show it in the "DD/MM/YYYY" format.

A test fiddle:
https://fiddle.sencha.com/#fiddle/i66

- My dataFormat and convert function are properly set.
- The format and submitFormat of the editor are set.
- I even checked the dirtychange event, and the field is set dirty when using the cell editing plugin.

BUT, there is no call to the update api in the store, here to fake_script, when changing the values in the editor.

It does work when I remove the convert method in the date field.

I'm using Ext 5.1.0

joel.watson
12 Feb 2015, 11:57 AM
Here's my use case:

I have a server which returns date on the "YYYY-MM-DD" format, including the "0001-01-01" value when a field is empty.
I want to show it in the "DD/MM/YYYY" format.

A test fiddle:
https://fiddle.sencha.com/#fiddle/i66

- My dataFormat and convert function are properly set.
- The format and submitFormat of the editor are set.
- I even checked the dirtychange event, and the field is set dirty when using the cell editing plugin.

BUT, there is no call to the update api in the store, here to fake_script, when changing the values in the editor.

It does work when I remove the convert method in the date field.

I'm using Ext 5.1.0

Hi pgarlaud--

If you remove the "record" arguments from the convert method, it should work. Passing the second argument treats the fields as a calculated field, which are "persist:false" by default. You could also set persist:true directly and it should work.

http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.field.Field

Also, just for reference, the format argument on the datefield should be "dateFormat", instead of "dataFormat".

I've included a revised Fiddle showing it working as expected.

I hope that helps!
Thanks!
Joel

i6n

pgarlaud
13 Feb 2015, 12:38 AM
Hello, would be nice if such a critical behaviour was explained in detail in the doc of convert()! My problem is that I'm using the rec parameter to access a static function of my model class:
public function convert(val, record) { return record.self.parseDate(val); } Any ideas how to simulate this without the second parameter? Thanks for your answer already. PS: `dataFormat` was indeed a typo.

joel.watson
13 Feb 2015, 6:19 AM
Hello, would be nice if such a critical behaviour was explained in detail in the doc of convert()! My problem is that I'm using the rec parameter to access a static function of my model class:
public function convert(val, record) { return record.self.parseDate(val); } Any ideas how to simulate this without the second parameter? Thanks for your answer already. PS: `dataFormat` was indeed a typo.

You can still use the second parameter, but you'll need to set persist: true explicitly since calculated fields are persist: false by default.