Created
May 25, 2012 14:36
-
-
Save wingspan/2788469 to your computer and use it in GitHub Desktop.
ExtJS ComboBox auto-configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Ext.namespace('wspt.form'); | |
| /** | |
| * This plugin enables a combobox (or subtype) to configure its "valueField" and "displayField" | |
| * from the metadata defined in a JsonStore. | |
| */ | |
| wspt.form.ComboConfigPlugin = Ext.extend(Object, { | |
| init : function (combo) { | |
| function setComboFields (store, meta) { | |
| // ID field maps to combo value | |
| this.valueField = meta.idProperty; | |
| // for lack of better choice, use the first field as the display | |
| this.displayField = store.fields.first().name; | |
| // the template might have been created when "displayField" was undefined. Fix that. | |
| if (this.tpl) { | |
| this.tpl = this.tpl.replace("undefined", this.displayField); | |
| this.view.tpl = new Ext.XTemplate(this.tpl) | |
| } | |
| } | |
| combo.store.on('metachange', setComboFields, combo, {single: true}); | |
| } | |
| }); | |
| Ext.preg('wsptComboConfigPlugin', wspt.form.ComboConfigPlugin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment