diff --git a/LDK/resources/web/LDK/plugin/UserEditableCombo.js b/LDK/resources/web/LDK/plugin/UserEditableCombo.js index c3ce9a2d..a4455866 100644 --- a/LDK/resources/web/LDK/plugin/UserEditableCombo.js +++ b/LDK/resources/web/LDK/plugin/UserEditableCombo.js @@ -12,6 +12,7 @@ Ext4.define('LDK.plugin.UserEditableCombo', { alias: 'plugin.ldk-usereditablecombo', allowChooseOther: true, + useBracketsForUnknownValues: false, init: function(combo) { this.combo = combo; @@ -84,6 +85,7 @@ Ext4.define('LDK.plugin.UserEditableCombo', { var rec = this.store.createModel({}); rec.set(this.valueField, val); rec.set(this.displayField, val); + rec.set("invalid", true); this.store.add(rec); }, @@ -95,6 +97,47 @@ Ext4.define('LDK.plugin.UserEditableCombo', { } }); + if (this.useBracketsForUnknownValues) { + let innerTpl = 'this.formatLookup(values)'; + + const innerTplWrap = this.combo?.listConfig?.getInnerTpl(); + if (typeof innerTplWrap === 'string') { + innerTpl = innerTplWrap.replaceAll('values', innerTpl); + } + else if (Array.isArray(innerTplWrap)) { + innerTpl = innerTplWrap.map(t => t.replaceAll('values', innerTpl)); + } + else { + innerTpl = '{[' + innerTpl + ']}'; + } + + Ext4.override(combo, { + tpl: Ext4.create('Ext.XTemplate', + '', + { + formatLookup: function(value) { + const val = value[this.field.displayField] || value[this.field.valueField] || ''; + if (Ext4.isEmpty(val)) { + return ''; + } + + if (value.invalid) { + return '[' + LABKEY.Utils.encodeHtml(val) + ']'; + } + + return LABKEY.Utils.encodeHtml(val); + } + } + ) + }); + } + combo.store.on('add', this.onStoreAdd, this); combo.store.on('load', combo.ensureValueInStore, combo); combo.store.on('beforerender', combo.ensureValueInStore, combo);