From 78fe3316a8cb84ffd26b2bcbec66d90cf679c4f0 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 27 May 2025 06:32:17 -0700 Subject: [PATCH 1/4] Add tpl to bracket invalid lookups --- .../web/LDK/plugin/UserEditableCombo.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/LDK/resources/web/LDK/plugin/UserEditableCombo.js b/LDK/resources/web/LDK/plugin/UserEditableCombo.js index c3ce9a2d..49d482d4 100644 --- a/LDK/resources/web/LDK/plugin/UserEditableCombo.js +++ b/LDK/resources/web/LDK/plugin/UserEditableCombo.js @@ -84,6 +84,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); }, @@ -92,7 +93,30 @@ Ext4.define('LDK.plugin.UserEditableCombo', { this.addValueIfNeeded(val); this.callOverridden(arguments); - } + }, + 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); From 6816e4e5e528b5f099b0b115e54cedb70894e439 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 27 May 2025 07:32:46 -0700 Subject: [PATCH 2/4] opt in --- LDK/resources/web/LDK/plugin/UserEditableCombo.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LDK/resources/web/LDK/plugin/UserEditableCombo.js b/LDK/resources/web/LDK/plugin/UserEditableCombo.js index 49d482d4..66c1db34 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; @@ -109,7 +110,7 @@ Ext4.define('LDK.plugin.UserEditableCombo', { return ''; } - if (value.invalid) { + if (this.field.userEditablePlugin.useBracketsForUnknownValues && value.invalid) { return '[' + LABKEY.Utils.encodeHtml(val) + ']'; } From a2abf21fdd085eda536729b95c974c660e2ac4fd Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 27 May 2025 09:36:49 -0700 Subject: [PATCH 3/4] Opt in refactor. Less intrusive --- .../web/LDK/plugin/UserEditableCombo.js | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/LDK/resources/web/LDK/plugin/UserEditableCombo.js b/LDK/resources/web/LDK/plugin/UserEditableCombo.js index 66c1db34..66cab4d5 100644 --- a/LDK/resources/web/LDK/plugin/UserEditableCombo.js +++ b/LDK/resources/web/LDK/plugin/UserEditableCombo.js @@ -94,31 +94,36 @@ Ext4.define('LDK.plugin.UserEditableCombo', { this.addValueIfNeeded(val); this.callOverridden(arguments); - }, - tpl: Ext4.create('Ext.XTemplate', - '
    ', - '', - '
  • ', - '{[this.formatLookup(values)]}', - '
  • ', - '
    ', - '
', - { - formatLookup: function(value) { - const val = value[this.field.displayField] || value[this.field.valueField] || ''; - if (Ext4.isEmpty(val)) { - return ''; - } + } + }); - if (this.field.userEditablePlugin.useBracketsForUnknownValues && value.invalid) { - return '[' + LABKEY.Utils.encodeHtml(val) + ']'; + if (this.useBracketsForUnknownValues) { + Ext4.override(combo, { + tpl: Ext4.create('Ext.XTemplate', + '
    ', + '', + '
  • ', + '{[this.formatLookup(values)]}', + '
  • ', + '
    ', + '
', + { + 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); } - - return LABKEY.Utils.encodeHtml(val); } - } - ) - }); + ) + }); + } combo.store.on('add', this.onStoreAdd, this); combo.store.on('load', combo.ensureValueInStore, combo); From d2cc3bc6e0f1a20857fb6541bb6e824c34d7a702 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Wed, 28 May 2025 04:51:29 -0700 Subject: [PATCH 4/4] commit for posterity --- LDK/resources/web/LDK/plugin/UserEditableCombo.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/LDK/resources/web/LDK/plugin/UserEditableCombo.js b/LDK/resources/web/LDK/plugin/UserEditableCombo.js index 66cab4d5..a4455866 100644 --- a/LDK/resources/web/LDK/plugin/UserEditableCombo.js +++ b/LDK/resources/web/LDK/plugin/UserEditableCombo.js @@ -98,12 +98,25 @@ 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', '
    ', '', '
  • ', - '{[this.formatLookup(values)]}', + '' + innerTpl, '
  • ', '
    ', '
',