me.callParent(arguments);
},
+ config: {
+ skipEmptyText: false,
+ notFoundIsValid: false,
+ deleteEmpty: false,
+ },
+
// needed to trigger onKeyUp etc.
enableKeyEvents: true,
editable: false,
+ triggers: {
+ clear: {
+ cls: 'pmx-clear-trigger',
+ weight: -1,
+ hidden: true,
+ handler: function() {
+ var me = this;
+ me.setValue('');
+ },
+ },
+ },
+
+ setValue: function(value) {
+ var me = this;
+ let empty = Ext.isArray(value) ? !value.length : !value;
+ me.triggers.clear.setVisible(!empty && me.allowBlank);
+ return me.callParent([value]);
+ },
+
// override ExtJS method
// if the field has multiSelect enabled, the store is not loaded, and
// the displayfield == valuefield, it saves the rawvalue as an array
}
},
+ getSubmitData: function() {
+ var me = this;
+
+ let data = null;
+ if (!me.disabled && me.submitValue) {
+ let val = me.getSubmitValue();
+ if (val !== null) {
+ data = {};
+ data[me.getName()] = val;
+ } else if (me.getDeleteEmpty()) {
+ data = {};
+ data.delete = me.getName();
+ }
+ }
+ return data;
+ },
+
+ getSubmitValue: function() {
+ var me = this;
+
+ var value = me.callParent();
+ if (value !== '') {
+ return value;
+ }
+
+ return me.getSkipEmptyText() ? null: value;
+ },
+
+ setAllowBlank: function(allowBlank) {
+ this.allowBlank = allowBlank;
+ this.validate();
+ },
+
// override ExtJS protected method
onBindStore: function(store, initial) {
var me = this,
extraKeySpec = {
byValue: {
rootProperty: 'data',
- unique: false
- }
+ unique: false,
+ },
};
extraKeySpec.byValue.property = me.valueField;
store.setExtraKeys(extraKeySpec);
} else {
extraKeySpec.byText = {
rootProperty: 'data',
- unique: false
+ unique: false,
};
extraKeySpec.byText.property = me.displayField;
store.setExtraKeys(extraKeySpec);
rootProperty: 'data',
extraKeys: {
byInternalId: {
- property: 'internalId'
+ property: 'internalId',
},
byValue: {
property: me.valueField,
- rootProperty: 'data'
- }
+ rootProperty: 'data',
+ },
},
// Whenever this collection is changed by anyone, whether by this field adding to it,
// or the BoundList operating, we must refresh our value.
listeners: {
beginupdate: me.onValueCollectionBeginUpdate,
endupdate: me.onValueCollectionEndUpdate,
- scope: me
- }
+ scope: me,
+ },
};
// This becomes our collection of selected records for the Field.
store: store,
listeners: {
scope: me,
- lastselectedchanged: me.updateBindSelection
- }
+ lastselectedchanged: me.updateBindSelection,
+ },
});
if (!initial) {
pageSize: me.pageSize,
tpl: me.tpl,
selModel: me.pickerSelectionModel,
- focusOnToFront: false
+ focusOnToFront: false,
}, me.listConfig, me.defaultListConfig);
picker = me.picker || Ext.widget(pickerCfg);
if (!picker.initialConfig.maxHeight) {
picker.on({
beforeshow: me.onBeforePickerShow,
- scope: me
+ scope: me,
});
}
picker.getSelectionModel().on({
beforeselect: me.onBeforeSelect,
beforedeselect: me.onBeforeDeselect,
focuschange: me.onFocusChange,
- selectionChange: function (sm, selectedRecords) {
+ selectionChange: function(sm, selectedRecords) {
var me = this;
if (selectedRecords.length) {
me.setValue(selectedRecords);
me.fireEvent('select', me, selectedRecords);
}
},
- scope: me
+ scope: me,
});
// hack for extjs6
// it does not select the item
// instead we hide the picker
if (!me.multiSelect) {
- picker.on('itemclick', function (sm,record) {
+ picker.on('itemclick', function(sm, record) {
if (picker.getSelection()[0] === record) {
picker.hide();
}
return picker;
},
+ clearLocalFilter: function() {
+ var me = this,
+ filter = me.queryFilter;
+
+ if (filter) {
+ me.queryFilter = null;
+ me.changingFilters = true;
+ me.store.removeFilter(filter, true);
+ me.changingFilters = false;
+ }
+ },
+
+ isValueInStore: function(value) {
+ var me = this;
+ var store = me.store;
+ var found = false;
+
+ if (!store) {
+ return found;
+ }
+
+ // Make sure the current filter is removed before checking the store
+ // to prevent false negative results when iterating over a filtered store.
+ // All store.find*() method's operate on the filtered store.
+ if (me.queryFilter && me.queryMode === 'local' && me.clearFilterOnBlur) {
+ me.clearLocalFilter();
+ }
+
+ if (Ext.isArray(value)) {
+ Ext.Array.each(value, function(v) {
+ if (store.findRecord(me.valueField, v)) {
+ found = true;
+ return false; // break
+ }
+ });
+ } else {
+ found = !!store.findRecord(me.valueField, value);
+ }
+
+ return found;
+ },
+
+ validator: function(value) {
+ var me = this;
+
+ if (!value) {
+ return true; // handled later by allowEmpty in the getErrors call chain
+ }
+
+ // we normally get here the displayField as value, but if a valueField
+ // is configured we need to get the "actual" value, to ensure it is in
+ // the store. Below check is copied from ExtJS 6.0.2 ComboBox source
+ //
+ // we also have to get the 'real' value if the we have a mulitSelect
+ // Field but got a non array value
+ if (me.valueField && me.valueField !== me.displayField ||
+ me.multiSelect && !Ext.isArray(value)) {
+ value = me.getValue();
+ }
+
+ if (!(me.notFoundIsValid || me.isValueInStore(value))) {
+ return gettext('Invalid Value');
+ }
+
+ return true;
+ },
+
+ // validate after enabling a field, otherwise blank fields with !allowBlank
+ // are sometimes not marked as invalid
+ setDisabled: function(value) {
+ this.callParent([value]);
+ this.validate();
+ },
+
initComponent: function() {
var me = this;
Ext.apply(me, {
queryMode: 'local',
- matchFieldWidth: false
+ matchFieldWidth: false,
});
- Ext.applyIf(me, { value: ''}); // hack: avoid ExtJS validate() bug
+ Ext.applyIf(me, { value: '' }); // hack: avoid ExtJS validate() bug
Ext.applyIf(me.listConfig, { width: 400 });
}
var found = false;
if (def) {
- if (Ext.isArray(def)) {
- Ext.Array.each(def, function(v) {
- if (store.findRecord(me.valueField, v)) {
- found = true;
- return false; // break
- }
- });
- } else {
- found = store.findRecord(me.valueField, def);
- }
+ found = me.isValueInStore(def);
}
if (!found) {
if (me.autoSelect && rec && rec.data) {
def = rec.data[me.valueField];
me.setValue(def, true);
- } else {
- me.setValue(me.editable ? def : '', true);
+ } else if (!me.allowBlank && !(Ext.isArray(def) ? def.length : def)) {
+ me.setValue(def);
+ if (!me.notFoundIsValid && !me.isDisabled()) {
+ me.markInvalid(me.blankText);
+ }
}
}
}
});
- }
+ },
});