Skip to content

Commit 38db543

Browse files
committed
Allow UserEditableCombo to work when displayField != valueField if they are both strings. This is effectively how it operated all along
1 parent 6f11e62 commit 38db543

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

LDK/resources/web/LDK/plugin/UserEditableCombo.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Ext4.define('LDK.plugin.UserEditableCombo', {
2222
Ext4.override(combo, {
2323
onListSelectionChange: function(list, selectedRecords) {
2424
var val;
25-
if(selectedRecords && selectedRecords.length && selectedRecords.length == 1)
25+
if(selectedRecords && selectedRecords.length && selectedRecords.length === 1)
2626
val = selectedRecords[0].get(this.displayField);
2727

28-
if (this.userEditablePlugin.allowChooseOther && val == 'Other'){
28+
if (this.userEditablePlugin.allowChooseOther && val === 'Other'){
2929
this.getPicker().getSelectionModel().deselectAll(true); //note: we need to clear selection in case other is clicked twice in a row
3030
this.userEditablePlugin.onClickOther();
3131
this.collapse();
@@ -44,10 +44,6 @@ Ext4.define('LDK.plugin.UserEditableCombo', {
4444
if (Ext4.isEmpty(val))
4545
return;
4646

47-
//only applies if display/value are the same. otherwise we cannot accurately do this
48-
if (this.valueField != this.displayField)
49-
return;
50-
5147
if (val instanceof Ext4.data.Model || Ext4.isArray(val)){
5248
return; //if setting value using a record, it is probably in the store
5349
}
@@ -66,17 +62,29 @@ Ext4.define('LDK.plugin.UserEditableCombo', {
6662
return;
6763
}
6864

65+
//only applies if display/value are the same. otherwise we cannot accurately do this
66+
if (this.valueField !== this.displayField) {
67+
var type1 = this.store.model.fields.get(this.valueField) && this.store.model.fields.get(this.displayField).type ? this.store.model.fields.get(this.valueField).type.type : null;
68+
var type2 = this.store.model.fields.get(this.displayField) && this.store.model.fields.get(this.displayField).type ? this.store.model.fields.get(this.displayField).type.type : null;
69+
70+
if (type1 !== 'string' || type2 !== 'string') {
71+
return;
72+
}
73+
}
74+
6975
if (Ext4.isObject(val)){
7076
console.log(val);
7177
return;
7278
}
7379

7480
var recIdx = this.store.findExact(this.valueField, val);
75-
if (recIdx != -1)
81+
if (recIdx !== -1)
7682
return;
7783

7884
var rec = this.store.createModel({});
7985
rec.set(this.valueField, val);
86+
rec.set(this.displayField, val);
87+
8088
this.store.add(rec);
8189
},
8290

@@ -151,7 +159,7 @@ Ext4.define('LDK.plugin.UserEditableCombo', {
151159
},
152160

153161
onPrompt: function(btn, val){
154-
if (btn == 'ok') {
162+
if (btn === 'ok') {
155163
this.addNewValue(val);
156164
}
157165

@@ -213,7 +221,7 @@ Ext4.define('LDK.plugin.UserEditableCombo', {
213221
return;
214222
}
215223

216-
idx = idx || (this.combo.store.getCount() == 0 ? 0 : this.combo.store.getCount() - 1);
224+
idx = idx || (this.combo.store.getCount() === 0 ? 0 : this.combo.store.getCount() - 1);
217225
this.combo.store.insert(idx, [this.combo.store.createModel(data)]);
218226

219227
return this.combo.store.getAt(idx);

0 commit comments

Comments
 (0)