Skip to content

Support formmethod and formaction in ViewTransitions#9084

Merged
matthewp merged 4 commits intomainfrom
formmethod
Nov 13, 2023
Merged

Support formmethod and formaction in ViewTransitions#9084
matthewp merged 4 commits intomainfrom
formmethod

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

Changes

  • Adds takes into account: <button type="submit" formmethod="post" formaction="/other">.
  • This is a way to have a button which modifies the action and/or method of the parent form.

Testing

  • Test added

Docs

N/A, bug fix

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Nov 13, 2023

🦋 Changeset detected

Latest commit: 8a9eb44

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Nov 13, 2023
@github-actions github-actions bot added the pr: docs A PR that includes documentation for review label Nov 13, 2023
}

const form = el as HTMLFormElement;
const submitter: HTMLButtonElement | null = ev.submitter as any;
Copy link
Copy Markdown
Member

@ematipico ematipico Nov 13, 2023

Choose a reason for hiding this comment

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

Is any the correct type? Should it be unknown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was being too clever with types, didn't need it, so removed it.

const formData = new FormData(form);
// Use the form action, if defined, otherwise fallback to current path.
let action = form.action ?? location.pathname;
let action = submitter?.getAttribute('formaction') ?? form.action ?? location.pathname;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let action = submitter?.getAttribute('formaction') ?? form.action ?? location.pathname;
const action = submitter?.getAttribute('formaction') ?? form.action ?? location.pathname;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

action is mutated in an if after this.

matthewp and others added 2 commits November 13, 2023 11:25
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
@matthewp matthewp merged commit 045e5ec into main Nov 13, 2023
@matthewp matthewp deleted the formmethod branch November 13, 2023 19:03
@astrobot-houston astrobot-houston mentioned this pull request Nov 13, 2023
natemoo-re pushed a commit that referenced this pull request Nov 22, 2023
* Support formmethod and formaction in ViewTransitions

* Adding a changeset

* Update .changeset/new-pets-fail.md

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>

* Be less clever

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants