-
12 Mar 2012 9:08 AM #1
Unanswered: An equivalent to getModelData() for setting field values?
Unanswered: An equivalent to getModelData() for setting field values?
I love that I can override getModelData() in my custom field and provide multiple values to be set in my record when the form is submitted, but I can't seem to figure out how to read multiple values from my record when Basic.loadRecord() is called. Where is my setModelData()??
Surely a complimentary function should exist, but I can't seem to find it. What's the point of setting multiple record values from a custom form element if, to set all the field values from a record, you have to put special code in your form?
-
12 Mar 2012 10:03 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
So basically you want to be able to execute uploadRecord and have it then execute setModelData to control how it sets the data onto the record?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
12 Mar 2012 10:21 AM #3
No, not at all. I want a Ext.form.Basic.setValues() to call a function on each of its fields that looks, by default in Ext.form.field.Field, like this:
which I can override in my custom field that deals with multiple values on the record like so:Code:setModelData: function(obj) { this.setValue(obj[this.name]); }
This is the compliment of what I can already do with getModelData():Code:setModelData: function(obj) { this.callParent(arguments); this.otherValueICareAbout1 = obj['otherValueICareAbout1']; this.otherValueICareAbout2 = obj['otherValueICareAbout2']; }
For instance, say I want to make a color picker to edit three values, red, green, and blue, on my record. It is currently trivial for my field to return all three values from getModelData(), but to set those into my field, my code calling form.loadRecord() or form.setValues() needs to be wise to the special needs of the color picker field type. It seems like it shouldn't have to be.Code:getModelData: function() { var obj = this.callParent(arguments); obj['otherValueICareAbout1'] = this.otherValueICareAbout1; obj['otherValueICareAbout2'] = this.otherValueICareAbout2; return obj; }
-
22 Jan 2013 6:25 AM #4
Indeed
Indeed
I just found getModelData(), very useful at first.
But since there is no "setModelData", it is useless. Or I missed something.
-
22 Jan 2013 6:40 AM #5
My Plugin
My Plugin
Ok, here is a plugin to easily add a setModelSupport().
Since I don't want to mess too much with the loadRecord() method, it actually call all setModelData() methods after the original method.
Code:/** * Plugin (ptype = 'formsetmodeldata') that calls the "setModelData" * for Fields which have this method defined, when "loadRecord" is set. */ Ext.define('Ext.ux.plugin.form.SetModelData', { extend: 'Ext.AbstractPlugin', alias: 'plugin.formsetmodeldata', constructor: function() { this.callParent(arguments); }, init: function(formPanel) { basicForm = formPanel.getForm(); Ext.override(basicForm, { loadRecord : function (record) { this.callParent(arguments); fields = formPanel.query('[setModelData]'); Ext.each(fields, function(field) { if (Ext.isFunction(field.setModelData)) field.setModelData(record.data); }); } } ); } });
PS: Ext.ComponentQuery is awesome.


Reply With Quote