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
Address field: Add super-scaffolding support, document new field and document updating dependent-fields in a form #534
Address field: Add super-scaffolding support, document new field and document updating dependent-fields in a form #534
Conversation
I'm trying to find a good name, a good file name / title, for the new pattern introduced with the The trick uses:
Some names I've got down:
|
@pascallaliberte I personally like Looking at the code here... Lines 41 to 48 in ffe2aa3
I think the name Other thoughtsIf I would change anything, I might call it End goal
I'm not sure I understand what the end goal is, do we want a new name for a file that we're adding in |
@gazayas Thanks for chiming in! I appreciate it. The end goal: document the pattern for uses outside the address field country > region + postal code field updates. So I'm looking for naming the pattern, creating a page in the docs with a title and a short-ish slug. Something catchy. This pattern is a Bullet Train first, being a super-scaffold friendly no-config way to update fields on a form based on another field. I also think it's a Rails first, so I think it's worth giving BT a marketing boost from it, and hence giving it a solid name. I also like "Turbo Reactive Field Changes". One drawback: I think it's missing the magic that It's not just that Turbo is involved. It's that this technique is low-config. Thoughts? |
I see, so it's not just specifically for the scope of our address partial, but for the pattern in general. Good point about |
Of the proposed names I like "Magic Dependent Fields" the best. Partly because it's the shortest, and partly because I think it best describes what the feature is about, without the name being pegged to how it does it. I'd maybe also drop "Magic" and just call it "Dependent Fields". |
I'm having a bit of a hard time understanding the underlying API here, it seems like we're missing some wiring somewhere particularly given <%= form_with model: @tangible_thing, data: { controller: "form" } do |form| %>
<%# Ensure we fire off a request on change, but route it into the dedicated frame %>
<%= form.select :country_id, data: { action: "change->form#requestSubmit", turbo_frame: form.refreshed_field_name(:country_id) } %>
<%= turbo_frame_tag form.refreshed_field_name(:country_id) do %>
<%= render "addresses/form" %>
<% end %>
<% end %> |
@kaspth I appreciate this. I'll think it over some more. |
@kaspth In our case, I was looking for a way that would fit a few constraints:
But the API could be cleaned up, to your credit. I did the following changes:
@gazayas, @jagthedrummer: I'm dropping "Turbo" and "Magic" from the name of this feature because of how the two concepts (Dependent Fields Pattern and Dependent Fields Frame) are explained, it really feels more like a sober toolkit than a central innovation. It's also found within a heading of "Dynamic Forms and Dependent Fields" in the docs, for scalability and "obviousness"(?). Reactions? Rebuttals? |
@pascallaliberte Sounds good to me! After reading @jagthedrummer's comment too a naming convention that has a focus on |
bullet_train-fields/app/javascript/controllers/dependent_fields_frame_controller.js
Show resolved
Hide resolved
@pascallaliberte great job! I just skimmed the code and docs and it looks a lot clearer to me. |
...views/showcase/previews/field_partials/attribute_partials/_about_attribute_partials.html.erb
Outdated
Show resolved
Hide resolved
...views/showcase/previews/field_partials/attribute_partials/_about_attribute_partials.html.erb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
bullet_train/docs/field-partials/dynamic-forms-dependent-fields.md
Outdated
Show resolved
Hide resolved
We'll move the conditional on the `disabled` property. And we'll also let the `dependent_fields_frame` underlying controller handle disabling the field automatically when the `turbo_frame` awaits updates. | ||
|
||
```erb | ||
<%= render "shared/fields/dependent_fields_frame", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically not relevant to this PR, but I keep thinking I should add a default Form Builder for Bullet Train, so we can get stuff like this out of the box:
<%= form.dependent_fields_frame :heard_from do |controller| %>
<%= form.text_field :heard_from_other, disabled: form.object&.heard_from != "other",
data: { "#{controller}-target": "field" %>
<% end %>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this documentation is really clear!
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
…ield Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like how this turned out. Great write up of everything. Nice work, @pascallaliberte!
Closes #533
This PR adds super-scaffolding support, documents the field and documents the self-updating form mechanism to be used elsewhere in forms.
address_field
to the super-scaffolding mechanismaddress_field
compound field partial, its large support for country and region choices out of the box.attributes/address
partial and its display options (one_line)country_id
selected). Resolves Selection in one super select affects options of another. bullet_train-fields#42