-
Notifications
You must be signed in to change notification settings - Fork 436
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
Add option to disable turbo for form or optin to forms. #419
Conversation
Seems to be no interest on this from the owners and as its behind now will close this off |
I think this is actually solid. Missed on the first go around. Please do update and I'll merge 👍 |
4a1a5c7
to
4b738d4
Compare
@dhh that it all updated with main. Assuming it passes the CI test should be good to merge |
Doh, forgot to run the linter check locally. I'll get those fixed up just now |
In large application upgrading from turbolinks to turbo requires all forms that use `render` to return validations errors needs to be updated with `status: :unprocessable_entity` to as in 4670f2b to. This makes it hard to upgrade as you ether have to have a single PR that upgrades all form (when you have over 400 forms is pretty risky) or disable all forms which again can be risky if you miss one before completing the upgrade. There are options but it would be great if you can could do this in turbo and save hours of work. To allow this I've added a `formMode` to the session so you can change the behaviour of turbo and how it interacts with forms. The mode is set via the `Tubro.setFormMode` option and can be set to one of 3 options: - "on" all forms will be submitted with turbo, this is the default - "off" forms will not be submitted with turbo - "optin" forms by default will not be submitted with turbo unless the form is annotated with `data-turbo="true"` attribute. Adding these options will allow user of turbo to decide how forms should work and make upgrading easier.
4b738d4
to
67ea576
Compare
That should be it good for another CI run if someone can kick off a run. |
Follow-up to hotwired#655 Follow-up to hotwired#419 This commit splits out a `form_mode_tests.ts` module separate from `form_submission_tests.ts`, along with a `form_mode.html` fixture file. Next, add test fixtures and test coverage for more thorough coverage of form mode, namely scenarios that submit a form without a submitter (for example, typing into an `<input type="text">` and pressing <kbd>enter</kbd>. Next, the `Turbo.setFormMode()` should be particular about its argument's value. This commit introduces a `FormMode = "on" | "off" | "optin"` type. Finally, rename `submitterIsNavigatable` to `submissionIsNavigatable`, and pass the `HTMLFormElement` and optional `HTMLElement` as a pair of arguments.
I've opened #658 to expand coverage to include |
Follow-up to hotwired#655 Follow-up to hotwired#419 This commit splits out a `form_mode_tests.ts` module separate from `form_submission_tests.ts`, along with a `form_mode.html` fixture file. Next, add test fixtures and test coverage for more thorough coverage of form mode, namely scenarios that submit a form without a submitter (for example, typing into an `<input type="text">` and pressing <kbd>enter</kbd>. Next, the `Turbo.setFormMode()` should be particular about its argument's value. This commit introduces a `FormMode = "on" | "off" | "optin"` type. Finally, rename `submitterIsNavigatable` to `submissionIsNavigatable`, and pass the `HTMLFormElement` and optional `HTMLElement` as a pair of arguments.
Follow-up to hotwired#655 Follow-up to hotwired#419 This commit splits out a `form_mode_tests.ts` module separate from `form_submission_tests.ts`, along with a `form_mode.html` fixture file. Next, add test fixtures and test coverage for more thorough coverage of form mode, namely scenarios that submit a form without a submitter (for example, typing into an `<input type="text">` and pressing <kbd>enter</kbd>. Next, the `Turbo.setFormMode()` should be particular about its argument's value. This commit introduces a `FormMode = "on" | "off" | "optin"` type. Finally, rename `submitterIsNavigatable` to `submissionIsNavigatable`, and pass the `HTMLFormElement` and optional `HTMLElement` as a pair of arguments.
Follow-up to hotwired#655 Follow-up to hotwired#419 This commit splits out a `form_mode_tests.ts` module separate from `form_submission_tests.ts`, along with a `form_mode.html` fixture file. Next, add test fixtures and test coverage for more thorough coverage of form mode, namely scenarios that submit a form without a submitter (for example, typing into an `<input type="text">` and pressing <kbd>enter</kbd>. Next, the `Turbo.setFormMode()` should be particular about its argument's value. This commit introduces a `FormMode = "on" | "off" | "optin"` type. Finally, rename `submitterIsNavigatable` to `submissionIsNavigatable`, and pass the `HTMLFormElement` and optional `HTMLElement` as a pair of arguments.
Follow-up to hotwired#655 Follow-up to hotwired#419 This commit splits out a `form_mode_tests.ts` module separate from `form_submission_tests.ts`, along with a `form_mode.html` fixture file. Next, add test fixtures and test coverage for more thorough coverage of form mode, namely scenarios that submit a form without a submitter (for example, typing into an `<input type="text">` and pressing <kbd>enter</kbd>. Next, the `Turbo.setFormMode()` should be particular about its argument's value. This commit introduces a `FormMode = "on" | "off" | "optin"` type. Finally, rename `submitterIsNavigatable` to `submissionIsNavigatable`, and pass the `HTMLFormElement` and optional `HTMLElement` as a pair of arguments.
Follow-up to #655 Follow-up to #419 This commit splits out a `form_mode_tests.ts` module separate from `form_submission_tests.ts`, along with a `form_mode.html` fixture file. Next, add test fixtures and test coverage for more thorough coverage of form mode, namely scenarios that submit a form without a submitter (for example, typing into an `<input type="text">` and pressing <kbd>enter</kbd>. Next, the `Turbo.setFormMode()` should be particular about its argument's value. This commit introduces a `FormMode = "on" | "off" | "optin"` type. Finally, rename `submitterIsNavigatable` to `submissionIsNavigatable`, and pass the `HTMLFormElement` and optional `HTMLElement` as a pair of arguments.
Is this feature documented anywhere? Should it be? Google search for Lack of documentation makes it hard to discover, and hard to know what the intended correct behavior is. People seem to find out about this feature either from this PR, or from various StackOverflow and blog posts, which may or may not contain current correct information. There are also confusing cases that could be addresed, such as in this Stackoverflow answer. |
In large application upgrading from turbolinks to turbo requires all
forms that use
render
to return validations errors needs to beupdated with
status: :unprocessable_entity
to as in #39 to.This makes it hard to upgrade as you ether have to have a single PR that
upgrades all form (when you have over 400 forms is pretty risky) or
disable all forms which again can be risky if you miss one before
completing the upgrade.
There are other options but it would be great if you can could do this in
turbo and save hours of work.
To allow this I've added a
formMode
to the session so you can changethe behaviour of turbo and how it interacts with forms.
The mode is set via the
Tubro.setFormMode
option and can be set to oneof 3 options:
form is annotated with
data-turbo="true"
attribute.Adding these options will allow user of turbo to decide how forms should
work and make upgrading easier.