partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

ReloadableComboBox.js (1319B)


      1 Ext.define("PartKeepr.ReloadableComboBox", {
      2     extend: "Ext.form.field.ComboBox",
      3     alias: 'widget.ReloadableComboBox',
      4     displayField: 'name',
      5     valueField: '@id',
      6     autoSelect: true,
      7     queryMode: 'local',
      8     triggerAction: 'all',
      9     forceSelection: true,
     10     editable: true,
     11     triggers: {
     12         reload: {
     13             cls: "x-form-reload-trigger",
     14             weight: -1,
     15             handler: function ()
     16             {
     17                 this.store.load();
     18             },
     19             scope: 'this'
     20         }
     21     },
     22     initComponent: function ()
     23     {
     24         this.listenersStore = this.store.on({
     25             scope: this,
     26             // Workaround to remember the value when loading
     27             beforeload: function ()
     28             {
     29                 this._oldValue = this.getSelection();
     30             },
     31             // Set the old value when load is complete
     32             load: function ()
     33             {
     34                 this.setSelection(this._oldValue);
     35             }
     36         });
     37 
     38         this.callParent();
     39     },
     40     getErrors: function (value)
     41     {
     42         var errors = this.callParent([value]);
     43 
     44         if (this.allowBlank !== true) {
     45             if (this.getValue() === null) {
     46                 errors.push(i18n("This field is required"));
     47             }
     48         }
     49 
     50         return errors;
     51     }
     52 });