From 991986bb7e4ce797dd2e8d4ab3195ad3d9e35ca9 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Mon, 19 May 2025 15:32:41 -0700 Subject: [PATCH 1/7] Broken lookups in forms --- ehr/resources/web/ehr/DataEntryUtils.js | 21 +++++++++++++++ ehr/resources/web/ehr/data/StoreCollection.js | 17 ++++++++++++ .../web/ehr/ehr_ext4_dataEntry.lib.xml | 1 + ehr/resources/web/ehr/grid/Panel.js | 9 +++++++ ehr/resources/web/ehr/panel/DataEntryPanel.js | 1 + ehr/resources/web/ehr/plugin/CellEditing.js | 26 +++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 ehr/resources/web/ehr/plugin/CellEditing.js diff --git a/ehr/resources/web/ehr/DataEntryUtils.js b/ehr/resources/web/ehr/DataEntryUtils.js index 180149642..f1b12c4fe 100644 --- a/ehr/resources/web/ehr/DataEntryUtils.js +++ b/ehr/resources/web/ehr/DataEntryUtils.js @@ -472,6 +472,21 @@ EHR.DataEntryUtils = new function(){ return cfg; }, + handleColInvalidLookups: function(recName, fieldName, recordStore, fieldStore) { + recordStore.each(rec => { + let recData = rec.get(recName); + if (recData && !recordStore.hasInvalidLookups && fieldStore.findExact(fieldName, recData) === -1) { + rec.set(recName, '[' + recData + ']'); + recordStore.hasInvalidLookups = true; + recordStore.sectionCfg.fieldConfigs.forEach(f => { + if (f.name === recName) { + f.hasInvalidLookups = true; + } + }, this); + } + }) + }, + getColumnConfigFromMetadata: function(meta, grid){ var col = {}; col.dataIndex = meta.dataIndex || meta.name; @@ -501,6 +516,12 @@ EHR.DataEntryUtils = new function(){ } meta.showTooltip = EHR.DataEntryUtils.shouldShowTooltips(); + + if (meta.lookup && col.editor.store) { + col.editor.store.on('load', function(store, y, z) { + EHR.DataEntryUtils.handleColInvalidLookups(col.dataIndex, col.editor.valueField, grid.store, store); + }); + } col.renderer = LABKEY.ext4.Util.getDefaultRenderer(col, meta, grid); //HTML-encode the column header diff --git a/ehr/resources/web/ehr/data/StoreCollection.js b/ehr/resources/web/ehr/data/StoreCollection.js index e3612bb1b..de258c8f8 100644 --- a/ehr/resources/web/ehr/data/StoreCollection.js +++ b/ehr/resources/web/ehr/data/StoreCollection.js @@ -203,6 +203,23 @@ Ext4.define('EHR.data.StoreCollection', { console.log(arguments); }, + normalizeInvalidLookups: function() { + this.clientStores.each(clientStore => { + if (clientStore.hasInvalidLookups) { + clientStore.sectionCfg.fieldConfigs.forEach(config => { + if (config.hasInvalidLookups) { + clientStore.each(rec => { + let val = rec.get(config.name); + if (val && val.startsWith('[')) { + rec.set(config.name, val.slice(1, -1)); + } + }); + } + }, this); + } + }, this); + }, + transformClientToServer: function(){ if (EHR.debug) console.log('client to server'); diff --git a/ehr/resources/web/ehr/ehr_ext4_dataEntry.lib.xml b/ehr/resources/web/ehr/ehr_ext4_dataEntry.lib.xml index 60557b71e..0af16f0ee 100644 --- a/ehr/resources/web/ehr/ehr_ext4_dataEntry.lib.xml +++ b/ehr/resources/web/ehr/ehr_ext4_dataEntry.lib.xml @@ -21,6 +21,7 @@