Skip to content
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

Support formmethod and formaction in ViewTransitions #9084

Merged
merged 4 commits into from
Nov 13, 2023
Merged

Conversation

matthewp
Copy link
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

Copy link

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
.changeset/new-pets-fail.md Outdated Show resolved Hide resolved
@@ -88,11 +88,14 @@ const { fallback = 'animate', handleForms } = Astro.props;
}

const form = el as HTMLFormElement;
const submitter: HTMLButtonElement | null = ev.submitter as any;
Copy link
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
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
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
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 matthewp merged commit 045e5ec into main Nov 13, 2023
13 checks passed
@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 <[email protected]>

* Be less clever

---------

Co-authored-by: Emanuele Stoppa <[email protected]>
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