View Full Version : An equivalent to getModelData() for setting field values?

12 Mar 2012, 9:08 AM
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
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?

12 Mar 2012, 10:21 AM
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:

setModelData: function(obj) {

which I can override in my custom field that deals with multiple values on the record like so:

setModelData: function(obj) {
this.otherValueICareAbout1 = obj['otherValueICareAbout1'];
this.otherValueICareAbout2 = obj['otherValueICareAbout2'];

This is the compliment of what I can already do with getModelData():

getModelData: function() {
var obj = this.callParent(arguments);
obj['otherValueICareAbout1'] = this.otherValueICareAbout1;
obj['otherValueICareAbout2'] = this.otherValueICareAbout2;
return obj;

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.

22 Jan 2013, 6:25 AM
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
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.

* 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() {



init: function(formPanel) {
basicForm = formPanel.getForm();
Ext.override(basicForm, {
loadRecord : function (record) {
fields = formPanel.query('[setModelData]');
Ext.each(fields, function(field) {
if (Ext.isFunction(field.setModelData))


PS: Ext.ComponentQuery is awesome.