Results 1 to 5 of 5

Thread: An equivalent to getModelData() for setting field values?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
      0  

    Question 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
      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
    224
    Vote Rating
    2
      0  

    Default 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

  5. #5
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    France
    Posts
    224
    Vote Rating
    2
      0  

    Default 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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •