Skip to content

Commit

Permalink
use simplier validation to include form attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jupapios committed May 1, 2024
1 parent 82581e7 commit 0b4abb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ function extractEvents(
const temp = submitter.ownerDocument.createElement('input');
temp.name = submitter.name;
temp.value = submitter.value;
const isOutsideForm = !form.contains(submitter);
if (isOutsideForm) {
if (form.id) {
temp.setAttribute('form', form.id);
}
(submitter.parentNode: any).insertBefore(temp, submitter);
Expand Down
19 changes: 11 additions & 8 deletions packages/react-dom/src/__tests__/ReactDOMForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,21 +494,24 @@ describe('ReactDOMForm', () => {
await act(async () => {
root.render(
<>
<button
form="form"
name="button"
value="outside"
ref={outsideButtonRef}>
Edit from outside
</button>
<form id="form" action={action}>
<form action={action}>
<input type="text" name="title" defaultValue="hello" />
<input type="submit" name="button" value="save" />
<input type="submit" name="button" value="delete" ref={inputRef} />
<button name="button" value="edit" ref={buttonRef}>
Edit
</button>
</form>
<form id="form" action={action}>
<input type="text" name="title" defaultValue="hello" />
</form>
<button
form="form"
name="button"
value="outside"
ref={outsideButtonRef}>
Button outside form
</button>
,
</>,
);
Expand Down

0 comments on commit 0b4abb2

Please sign in to comment.