@@ -38,7 +38,9 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
3838 name : observationField . name ,
3939 fieldLabel : observationField . fieldLabel ,
4040 labelWidth : observationField . labelWidth ,
41- width : observationField . width
41+ width : observationField . width ,
42+ // honor metadata that marks the field as never-enableable (see BulkEditPanel.getFieldConfigs)
43+ originalDisabled : observationField . originalDisabled
4244 } ;
4345
4446 categoryField . on ( 'change' , function ( field , newValue ) {
@@ -54,9 +56,15 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
5456
5557 reconfigureObservationField : function ( category ) {
5658 var store = this . observationTypesStore ;
57- if ( store . isLoading ( ) || ! store . getCount ( ) ) {
59+ // hasLoadedOnce (set in EHR.DataEntryUtils.getObservationTypesStore) distinguishes a pending
60+ // initial load from one that already returned no rows; for the latter we fall through to the
61+ // textfield default rather than waiting on a load event that will never fire
62+ if ( ! store . hasLoadedOnce ) {
5863 store . on ( 'load' , function ( ) {
59- this . reconfigureObservationField ( category ) ;
64+ // the dialog may have been closed before the store finished loading
65+ if ( this . panel && ! this . panel . isDestroyed ) {
66+ this . reconfigureObservationField ( category ) ;
67+ }
6068 } , this , { single : true } ) ;
6169 return ;
6270 }
@@ -67,14 +75,22 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
6775 return ;
6876 }
6977
78+ //note: we proceed even if the category cannot be found, to support records saved under a no-longer-supported category
79+ var rec = category ? store . findRecord ( 'value' , category ) : null ;
80+ var rawEditorConfig = ( rec && rec . get ( 'editorconfig' ) ) || null ;
81+
82+ // the category combo fires change on every keystroke, so skip the rebuild when the resolved
83+ // editor is unchanged; this avoids churn and preserves any value the user already entered
84+ if ( this . appliedEditorConfig !== undefined && this . appliedEditorConfig === rawEditorConfig ) {
85+ return ;
86+ }
87+
7088 var container = observationField . ownerCt ;
7189 var index = container . items . indexOf ( observationField ) ;
7290 //preserve the user's enable/disable toggle state across category changes
7391 var wasDisabled = observationField . isDisabled ( ) ;
7492
75- //note: we proceed even if the category cannot be found, to support records saved under a no-longer-supported category
76- var rec = category ? store . findRecord ( 'value' , category ) : null ;
77- var editorConfig = rec && rec . get ( 'editorconfig' ) ? Ext4 . decode ( rec . get ( 'editorconfig' ) ) : null ;
93+ var editorConfig = rawEditorConfig ? Ext4 . decode ( rawEditorConfig ) : null ;
7894 editorConfig = editorConfig || {
7995 xtype : 'textfield'
8096 } ;
@@ -84,7 +100,6 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
84100 delete cfg . value ;
85101 delete cfg . defaultValue ;
86102 cfg . allowBlank = true ;
87- cfg . originalDisabled = false ;
88103 cfg . disabled = wasDisabled ;
89104
90105 cfg = EHR . DataEntryUtils . ensureLookupPlugin ( cfg , false ) ;
@@ -93,5 +108,14 @@ Ext4.define('EHR.plugin.ClinicalObservationsBulkEdit', {
93108 var newField = Ext4 . widget ( cfg ) ;
94109 panel . addLabelToggle ( newField ) ;
95110 container . insert ( index , newField ) ;
111+
112+ // the databind plugin only registers listeners on the fields present at init, so register the
113+ // replacement explicitly to keep record syncing and validation consistent with the original field
114+ var databind = panel . getPlugin ( 'ehr-databind' ) ;
115+ if ( databind ) {
116+ databind . addFieldListener ( newField ) ;
117+ }
118+
119+ this . appliedEditorConfig = rawEditorConfig ;
96120 }
97121} ) ;
0 commit comments