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

fix: allow native form submission for <form target="_blank"> and <button formtarget="_blank"> #11936

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Mar 5, 2024

fixes #11931

This PR ensures that our client submit event listener allows the browser to make a native form submission to open a new tab if a form or button has the target="_blank" or formtarget="_blank" attribute. This should open the form response in a new tab for both GET and POST submissions.

Afaik the other target values such as _parent and _top should function similarly to _self where we just want to update the current page without refreshing (even if Kit is in an iframe).


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Mar 5, 2024

🦋 Changeset detected

Latest commit: d79d201

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@eltigerchino eltigerchino changed the title fix: allow native submission for forms and buttons with target="_blank" fix: allow native form submission for <form target="_blank"> and <button formtarget="_blank"> Mar 5, 2024
Copy link
Member

@ghostdevv ghostdevv left a comment

Choose a reason for hiding this comment

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

On line 2098 we could change it to use that target variable, I can't make a suggestion on github ui unfortunately

packages/kit/src/runtime/client/client.js Outdated Show resolved Hide resolved
@eltigerchino
Copy link
Member Author

On line 2098 we could change it to use that target variable, I can't make a suggestion on github ui unfortunately

Are you referring to const event_form = /** @type {HTMLFormElement} */ (event.target);? I can't find other references with target

@ghostdevv
Copy link
Member

Are you referring to const event_form = /** @type {HTMLFormElement} */ (event.target);? I can't find other references with target

I was talking about this line:

(submitter?.hasAttribute('formaction') && submitter?.formAction) || form.action

@eltigerchino
Copy link
Member Author

Are you referring to const event_form = /** @type {HTMLFormElement} */ (event.target);? I can't find other references with target

I was talking about this line:

(submitter?.hasAttribute('formaction') && submitter?.formAction) || form.action

I’m not sure if that’s right. We need the action property to determine the URL the form is sending the request to while the target property species with frame to open the response in

@eltigerchino eltigerchino added the forms Stuff relating to forms and form actions label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forms Stuff relating to forms and form actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

forms with target="_blank" doesnt open new window
2 participants