1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
    erikras is on a distinguished road

      0  

    Question 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?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,047
    Answers
    3493
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
    erikras is on a distinguished road

      0  

    Default


    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:

    Code:
    setModelData: function(obj) {
      this.setValue(obj[this.name]);
    }
    which I can override in my custom field that deals with multiple values on the record like so:

    Code:
    setModelData: function(obj) {
      this.callParent(arguments);
      this.otherValueICareAbout1 = obj['otherValueICareAbout1'];
      this.otherValueICareAbout2 = obj['otherValueICareAbout2'];
    }
    This is the compliment of what I can already do with getModelData():

    Code:
    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.

  4. #4
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    France
    Posts
    223
    Vote Rating
    0
    tof is on a distinguished road

      0  

    Default Indeed

    Indeed


    I just found getModelData(), very useful at first.

    But since there is no "setModelData", it is useless. Or I missed something.
    Christophe Badoit
    aka Tof

    My work : Lesiteimmo.com - Unobstrusive ExtJs Powered !

  5. #5
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    France
    Posts
    223
    Vote Rating
    0
    tof is on a distinguished road

      0  

    Default 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.
    Christophe Badoit
    aka Tof

    My work : Lesiteimmo.com - Unobstrusive ExtJs Powered !