Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions LDK/resources/web/LDK/plugin/UserEditableCombo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Ext4.define('LDK.plugin.UserEditableCombo', {

alias: 'plugin.ldk-usereditablecombo',
allowChooseOther: true,
useBracketsForUnknownValues: false,

init: function(combo) {
this.combo = combo;
Expand Down Expand Up @@ -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);
},
Expand All @@ -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',
'<ul class="x4-list-plain">',
'<tpl for=".">',
'<li role="option" class="x4-boundlist-item">',
'' + innerTpl,
'</li>',
'</tpl>',
'</ul>',
{
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);
Expand Down