Repository navigation
Replace turbo-fetch skill with dynamic-forms (turbo_form gem) #63
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --- | ||
| name: dynamic-forms | ||
| description: Build forms that change as they are filled in — cascading or dependent dropdowns, conditional fields and sections, option lists that depend on another field, STI type switches — with the turbo_form gem. Use when a form must update without a full page reload, when adding or changing a dynamic form, or when touching existing `turbo_fetch` routes, actions, or `turbo-form`/`turbo-fetch` Stimulus wiring. | ||
| metadata: | ||
| triggers: "dynamic form, dependent dropdown, cascading dropdown, conditional field, conditional section, dynamic options, update form on change, turbo_form, dynamic: true, dynamic_trigger, dynamic_action, expect_dynamic_form_request, turbo_fetch, turbo-fetch, turbo-form controller" | ||
| --- | ||
|
|
||
| # Dynamic Forms | ||
|
|
||
| The [turbo_form](https://github.com/OutlawAndy/turbo_form) gem is RoleModel's mechanism for dynamic form interaction. Every new dynamic form uses it. Do not write a `turbo_fetch` route, controller action, `.turbo_stream` view, or Stimulus controller for a form that turbo_form can drive. | ||
|
|
||
| The gem's [README](https://github.com/OutlawAndy/turbo_form#readme) is the API documentation. Read it before writing or changing a dynamic form. This skill does not restate it. | ||
|
|
||
| ## Setup | ||
|
|
||
| Check the `Gemfile` for `turbo_form`. If it is missing, add it and run `bin/rails generate turbo_form:install`, then draw the `:turbo_form` route concern on the resource: | ||
|
|
||
| ```ruby | ||
| resources :materials, concerns: :turbo_form | ||
| ``` | ||
|
|
||
| The engine defines the concern and the controller behavior. Do not define a `:turbo_form` or `:turbo_fetch` concern in `config/routes.rb`. | ||
|
|
||
| ## Shape | ||
|
|
||
| ```slim | ||
| = simple_form_for @material, dynamic: true do |f| | ||
| = f.input :type, input_html: { dynamic_trigger: true } | ||
| = f.input :substance, collection: @material.substances | ||
| ``` | ||
|
|
||
| The trigger re-renders the page through its own `new` or `edit` action with the submitted values assigned, so `@material.substances` answers for the type just picked. The options, conventions, `dynamic_action:` for custom Turbo Stream responses, and `expect_dynamic_form_request` for system tests are all in the README. | ||
|
|
||
| ## Existing `turbo_fetch` code | ||
|
|
||
| Older apps wire dynamic forms by hand: a `turbo_fetch` route concern, a `turbo_fetch` controller action, a `turbo_fetch.turbo_stream` view, a Stimulus controller registered as `turbo-form` or `turbo-fetch` (installed by `rolemodel_rails`, and unrelated to the turbo_form gem despite the name), and `expect_turbo_form_request` or `expect_turbo_fetch_request` in specs. That pattern is superseded. Do not extend it. When a change touches one of these forms, convert it to turbo_form and delete the route, action, view, and spec helper usage it no longer needs. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.