Skip to content

GH Issue 1793: Keep EHR forms from overwriting fields being edited - #1243

Merged
labkey-tchad merged 3 commits into
release26.11-SNAPSHOTfrom
26.11_fb_firefox153Fixes
Nov 18, 2026
Merged

labkey-tchad merged 3 commits into
release26.11-SNAPSHOTfrom
26.11_fb_firefox153Fixes

Conversation

@labkey-tchad

@labkey-tchad labkey-tchad commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

@labkey-tchad

Copy link
Copy Markdown
Member Author

Working through some Claude feedback

@bbimber

bbimber commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

@labkey-tchad , @labkey-martyp or @labkey-bpatel: I'm worried that tracking the field list, like this does, is a fragile approach. If the root issue is composite fields (which I can believe), would a more reliable solution to improve the "hasFocus" check by querying children and checking whether hasFocus=true on any of them? That avoids needing to maintain this list, which could get stale for unanticipated reasons.

Also, does pendingFieldIds ever get cleared?

I did not test, but I think something vaguely like this pseudocode would do it:

if (field.hasFocus){
  return true;
}

const focusedChildren = field.down('field[hasFocus]')  //this might need to use be field.query() or Ext4.ComponentQuery.query() instead
if (focusedChildren.length){
  return true;
}

@labkey-tchad

labkey-tchad commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

Claude response:

Yes, it's cleared on every flush: onFieldValueChange resets it, so a flag lives at most ~100 ms after the field's last change. It's now also cleared after bindRecord and unbindRecord, so flags from loading or unloading a record don't carry over.

The child-focus check is already there: isBeingEdited tests whether the field's element contains document.activeElement, which covers the date and time inputs of an xdatetime without relying on Ext's hasFocus. The pending flags cover what focus can't: the user has already left the field, but the buffered flush hasn't copied the value to the record yet. A store update or validation in that window would otherwise write the stale record value back over what they typed. Flushing the form first in onRecordUpdate would avoid the list, but it would clobber values a client store just set (e.g. DrugAdministrationClientStore).

The tracking is also tighter now: flags are keyed by the bound field rather than an xdatetime's inner date/time input, and only change sets them (blur still triggers the flush but doesn't flag the field).

@labkey-tchad
labkey-tchad requested a review from bbimber November 16, 2026 20:23
@bbimber

bbimber commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Whether Claude thinks so or not, my experience still says that all these extra listeners give you greater chance for some scenario not working the way you expect. The underlying problem does not sound especially complicated: composite fields dont correctly report hasFocus. If the child query works, it's a more "Ext-y" solution. Even if Ext is ancient now, all this code is operating within Ext's listeners and events. Making our own system over this isnt automatically a good idea, Claude approval or not.

@labkey-bpatel

labkey-bpatel commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

I think there are two separate issues here:

  1. Date-time fields losing edits: the inner date/time inputs have focus, but the parent field doesn't recognize it. The PR handles this in isBeingEdited, which treats the field as being edited when any of its inner inputs has focus: DataBind.js#L166. I agree that check should be enough here, without needing the pending list.
  2. Fields reverting after losing focus: the PR mentions an interval of "5" being saved as "15". I believe Selenium's clear() empties the field and moves focus away, but the change hasn't reached the record yet because of the 100ms delay. A record update in that window restores the old value, and the "5" is then typed after it. Since the field no longer has focus, a focus check can't help, and I think that's why the pending list, extra listeners and bookkeeping were added. @labkey-tchad, is that correct?

testAutomation#3286 already fixes 2 on the test side by typing over Ext4 fields instead of clearing them, so I'm wondering whether the extra bookkeeping is still needed. Could we drop it, keep only the focus fix, and rerun TNPRC_EHRTest and TNPRC_RequestsTest on Firefox 153? If they do not pass, we'll have a concrete failure that justifies it.

@labkey-tchad - thoughts?

@bbimber

bbimber commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

I think there are two separate issues here:

  1. Date-time fields losing edits: the inner date/time inputs have focus, but the parent field doesn't recognize it. The PR handles this in isBeingEdited, which treats the field as being edited when any of its inner inputs has focus: DataBind.js#L166. I agree that check should be enough here, without needing the pending list.
  2. Fields reverting after losing focus: the PR mentions an interval of "5" being saved as "15". I believe Selenium's clear() empties the field and moves focus away, but the change hasn't reached the record yet because of the 100ms delay. A record update in that window restores the old value, and the "5" is then typed after it. Since the field no longer has focus, a focus check can't help, and I think that's why the pending list, extra listeners and bookkeeping were added. @labkey-tchad, is that correct?

testAutomation#3286 already fixes 2 on the test side by typing over Ext4 fields instead of clearing them, so I'm wondering whether the extra bookkeeping is still needed. Could we drop it, keep only the focus fix, and rerun TNPRC_EHRTest and TNPRC_RequestsTest on Firefox 153? If they do not pass, we'll have a concrete failure that justifies it.

@labkey-tchad - thoughts?

I tend to agree with point 1. On point 2: I still dont have the full context, but Binal's post suggests the driver of this change is to address "super-human" interaction driven by selenium, rather than a condition that normal human interaction has been known to create. If true, I would urge caution about unintended consequences, and continue to make the point that adding a new custom scheme to cache changes (pendingFieldIds) is opening up potential issue that doesnt seem to be needed.

I am also interested to see how LabKey/LabDevKitModules#329 interacts with this. The concept behind the LDK PR does make sense, and would probably issue redundant events and buffering as they bubble up that would slow things down a little. These are certainly the most common composite (though not the only composite) field.

@labkey-tchad

Copy link
Copy Markdown
Member Author

testAutomation#3286 already fixes 2 on the test side

That is correct. Thank you.

return true;

var el = field.getEl();
return !!el && el.dom.contains(document.activeElement);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a fine way to do this check. I cant think of any reason Ext would render elements that doesnt conform to this expectation, but I also havent tested anything.

I think the following would work and is more Ext-y, but I dont feel strongly enough to hold up this PR on it:

if (field.hasFocus || field.down('[hasFocus]')?.length)

@labkey-tchad
labkey-tchad marked this pull request as ready for review November 17, 2026 17:18
@labkey-tchad
labkey-tchad merged commit ae434a7 into release26.11-SNAPSHOT Nov 18, 2026
9 of 10 checks passed
@labkey-tchad
labkey-tchad deleted the 26.11_fb_firefox153Fixes branch November 18, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants