Conversation
Contributor
Reviewer's GuideAdjusts ValidateForm’s JavaScript and Blazor logic so DisableAutoSubmitFormByEnter correctly prevents Enter-key form submission, including in modals and when the form DOM element changes, by tracking instances and rebinding handlers as needed. Sequence diagram for ValidateForm Enter-key handling and DOM updatessequenceDiagram
participant ValidateForm
participant JSRuntime
participant JSModule as ValidateForm_razor_js
participant DataStore as Data
participant Dom as FormElement
ValidateForm->>JSRuntime: InvokeVoidAsync(update, Id)
JSRuntime->>JSModule: update(id)
JSModule->>Dom: document.getElementById(id)
JSModule->>DataStore: Data.get(id)
alt [form element changed]
JSModule->>JSModule: dispose(id)
JSModule->>DataStore: Data.remove(id)
JSModule->>JSModule: unbind(form.el)
JSModule->>JSModule: init(id)
JSModule->>Dom: document.getElementById(id)
JSModule->>DataStore: Data.set(id, { el })
JSModule->>JSModule: bind(el)
JSModule->>Dom: EventHandler.on(keydown)
else [form element unchanged]
JSModule-->>ValidateForm: no changes
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
ValidateForm.razor.js'supdatefunction,const form = Data.get(id); if (el === form.el)will throw if no data has been stored for that id (e.g., wheninitwas never called), so add a null/undefined guard aroundformbefore accessingform.el. - Both
initandupdateassumedocument.getElementById(id)returns a valid element; consider returning early ifelis null to avoid passingnullintoData.set/EventHandler.onwhen the element is not present in the DOM (for example, in formless scenarios or after removal).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ValidateForm.razor.js`'s `update` function, `const form = Data.get(id); if (el === form.el)` will throw if no data has been stored for that id (e.g., when `init` was never called), so add a null/undefined guard around `form` before accessing `form.el`.
- Both `init` and `update` assume `document.getElementById(id)` returns a valid element; consider returning early if `el` is null to avoid passing `null` into `Data.set`/`EventHandler.on` when the element is not present in the DOM (for example, in formless scenarios or after removal).
## Individual Comments
### Comment 1
<location path="src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.js" line_range="18-20" />
<code_context>
+
+export function update(id) {
+ const el = document.getElementById(id);
+ const form = Data.get(id);
+
+ if (el === form.el) {
+ return;
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Handle missing Data entry in update() to avoid runtime errors.
If `update` runs before `init` stores the element, or after `Data.remove`, `Data.get(id)` can be `undefined`, causing `form.el` to throw. Add a null check and return early when `form` is falsy before accessing `form.el`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8282 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 769 769
Lines 34436 34445 +9
=========================================
+ Hits 34436 34445 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link issues
fixes #8281
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Ensure ValidateForm correctly disables Enter key auto-submit, including when used in modal or dynamically re-rendered forms.
Bug Fixes:
Enhancements: