-
Notifications
You must be signed in to change notification settings - Fork 0
fix: lvt-form:action routing, lvt-nav:no-intercept, unreserve action field #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,19 +151,31 @@ export class EventDelegator { | |
| } | ||
|
|
||
| // Auto-intercept forms (progressive complexity). | ||
| // Button name IS the action. Resolution order: | ||
| // 1. submitter.name (button name = action) | ||
| // 2. form.name (form name = action) | ||
| // 3. "" (server defaults to Submit()) | ||
| // Action resolution order: | ||
| // 1. lvt-form:action attribute (explicit routing) | ||
| // 2. submitter.name (button name = action) | ||
| // 3. form.name (form name = action) | ||
| // 4. "submit" (server defaults to Submit()) | ||
| // | ||
| // Note: lvt-action hidden field is a server-side progressive | ||
| // enhancement fallback (no-JS POST). The client does not read it; | ||
| // the server extracts it from form data directly. | ||
| if (!action && eventType === "submit" && element instanceof HTMLFormElement) { | ||
| if (!element.hasAttribute("lvt-form:no-intercept")) { | ||
| // Check for explicit routing attribute first. | ||
| // Empty string ("") falls through to submitter/form name resolution. | ||
| const explicitAction = element.getAttribute("lvt-form:action"); | ||
| const submitter = (e as SubmitEvent).submitter; | ||
| if (submitter instanceof HTMLButtonElement && submitter.name) { | ||
| action = submitter.name; | ||
| } else if (element.name) { | ||
| action = element.name; | ||
| if (explicitAction) { | ||
| action = explicitAction; | ||
| } else { | ||
| action = "submit"; | ||
| if (submitter instanceof HTMLButtonElement && submitter.name) { | ||
| action = submitter.name; | ||
| } else if (element.name) { | ||
| action = element.name; | ||
| } else { | ||
| action = "submit"; | ||
| } | ||
|
Comment on lines
+154
to
+178
|
||
| } | ||
| actionElement = element; | ||
|
|
||
|
|
@@ -233,13 +245,18 @@ export class EventDelegator { | |
| ).map((el) => (el as HTMLInputElement).name) | ||
| ); | ||
|
|
||
| // Determine which form field key is the action routing key | ||
| // (the submitter button's name, or "action" field) | ||
| // Exclude the submitter button's name from form data. | ||
| // The submitter's name is used as the action routing key in the | ||
| // button-name path — including it in data would be redundant. | ||
| // When lvt-form:action overrides routing, the button name is still | ||
| // excluded to avoid noisy payloads (the button is a UI control, | ||
| // not domain data). Button value and data-* attrs are collected below. | ||
| // "action" is NOT excluded — it's a normal data field. | ||
| const submitterForData = (targetElement as any).__lvtSubmitter as HTMLButtonElement | undefined; | ||
| const actionFieldName = submitterForData?.name || "action"; | ||
| const actionFieldName = submitterForData?.name; | ||
|
|
||
| formData.forEach((value, key) => { | ||
| if (key === actionFieldName || key === "action") return; | ||
| if (actionFieldName && key === actionFieldName) return; | ||
| if (checkboxNames.has(key)) { | ||
| message.data[key] = true; | ||
| this.logger.debug("Converted checkbox", key, "to true"); | ||
|
|
||
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description mentions a legacy
lvt-actionhidden field in the action resolution order, but this client code doesn't read any such field (and it isn't referenced elsewhere in the repo). Either implement that resolution step here or adjust the PR description to avoid advertising unsupported behavior.