-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address field: Add super-scaffolding support, document new field and …
…document updating dependent-fields in a form (#534) * start adding address_field to super-scaffolding * scaffold strong params for address_field, initialize empty before_action * fix set_default_(address) callback * linter * add showcase preview for address_field * docs: start address-field page, add to field-partials * fix available field partials table * title case the headings * add Attribute Partials section in showcase (under Field Partials) * add showcase preview for atttribute_partials/address * document customizing address output * showcase: pare down options for address_field * address_field: remove Address.new from sample code * add _dependent_fields_turbo_frame partial * address_field: use dependent_fields_turbo_frame * dependent_fields_turbo_frame: yield stimulus_controller name * address_field: dependent_fields_controller_name * address_field: use form.field_id for id of turbo_frame * docs/field-partials: add address_field link at the bottom * rename refresh-fields to dependent-fields-frame * docs: add dynamic-forms-dependent-fields * add showcase preview for _dependent_fields_frame * about_attribute_partials: compress to partial.body.optional.yield Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com> * about_attribute_partials: compress another partial.options.optional.yield Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com> * docs: add missing `do` on render Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com> * dependent_fields_frame showcase: clarify code example comment * super-select doc: add link to dynamic forms doc * buttons doc: add link to dynamic forms doc --------- Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
- Loading branch information
1 parent
06ffffd
commit a37318e
Showing
17 changed files
with
387 additions
and
39 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...elds/app/helpers/refresh_fields_helper.rb → .../helpers/dependent_fields_frame_helper.rb
This file contains 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 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 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 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 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 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
22 changes: 22 additions & 0 deletions
22
bullet_train-themes-light/app/views/showcase/previews/field_partials/_address_field.html.erb
This file contains 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,22 @@ | ||
<% showcase.description do %> | ||
When you're building forms, use Bullet Train's Field Partials for your form fields. They DRY-up all the presentation logic without needing a third-party dependency like Formtastic. | ||
<br/> | ||
<br/> | ||
Read much more about them in the extensive <a href="https://bullettrain.co/docs/field-partials" target="_blank">developer documentation</a>. | ||
<% end %> | ||
<% form_with model: Scaffolding::CompletelyConcrete::TangibleThing.new, url: "#" do |form| %> | ||
<% | ||
form.object.address_value = Address.new | ||
%> | ||
<% showcase.sample "Basic" do %> | ||
<%= render 'shared/fields/address_field', form: form, method: :address_value %> | ||
<% end %> | ||
<% end %> | ||
<%# To display further options use `showcase.options.x` as options with a block will clear the old options. See `_options.html.erb` for an example. %> | ||
<% showcase.options do |o| %> | ||
<% o.required :form, "Reference to the form object", type: "ActionView::Helpers::FormBuilder" %> | ||
<% o.required :method, "Attribute of the model" %> | ||
<% end %> |
45 changes: 45 additions & 0 deletions
45
...-themes-light/app/views/showcase/previews/field_partials/_dependent_fields_frame.html.erb
This file contains 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,45 @@ | ||
<% showcase.description do %> | ||
Follows the <a href="/docs/field-partials/dynamic-forms-dependent-fields.md" target="_blank">Dependent Fields Pattern (See developer documentation)</a> to display form fields that depend on the value of another field. | ||
<% end %> | ||
<% form_with model: Scaffolding::CompletelyConcrete::TangibleThing.new, url: "#" do |form| %> | ||
<% | ||
form.object.boolean_button_value = false | ||
%> | ||
<% showcase.sample "Basic" do %> | ||
<%# here we're wrapping the field to trap the `change` event %> | ||
<%= tag.div data: { | ||
'controller': "dependable", | ||
'action': 'change->dependable#updateDependents', | ||
'dependable-dependents-selector-value': "##{form.field_id(:button, :dependent_fields)}" | ||
} do %> | ||
<%= render "shared/fields/buttons", | ||
form: form, | ||
method: :boolean_button_value, | ||
other_options: { label: "Should I present more fields?" } %> | ||
<% end %> | ||
<%= render "shared/fields/dependent_fields_frame", | ||
id: form.field_id(:button, :dependent_fields), | ||
form: form, | ||
dependable_fields: [:boolean_button_value] do %> | ||
|
||
<div class="my-3"> | ||
<% if form.object.boolean_button_value %> | ||
<strong>More fields would be shown here.</strong> | ||
<% else %> | ||
<em>No fields should be shown here.</em> | ||
<% end %> | ||
</div> | ||
|
||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<%# To display further options use `showcase.options.x` as options with a block will clear the old options. See `_options.html.erb` for an example. %> | ||
<% showcase.options do |o| %> | ||
<% o.required :id, "id of the turbo_frame element" %> | ||
<% o.required :form, "Reference to the form object", type: "ActionView::Helpers::FormBuilder" %> | ||
<% o.required :dependable_fields, "Attributes of the model for the fields on whose values this frame depends", type: "Array" %> | ||
<% end %> |
15 changes: 15 additions & 0 deletions
15
...ws/showcase/previews/field_partials/attribute_partials/_about_attribute_partials.html.erb
This file contains 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,15 @@ | ||
<% showcase.description do %> | ||
Attribute partials are used to display a single attribute of a model, within an `index` table colum or the resource's `show` screen. | ||
|
||
Read more about them and about the form field partials in the extensive <a href="https://bullettrain.co/docs/field-partials" target="_blank">developer documentation</a>. | ||
<% end %> | ||
<%= partial.body.optional.yield Scaffolding::CompletelyConcrete::TangibleThing.new %> | ||
<%# To display further options use `showcase.options.x` as options with a block will clear the old options. See `_options.html.erb` for an example. %> | ||
<% showcase.options do |o| %> | ||
<% o.required :object, "Reference to the model object", type: "Object" %> | ||
<% o.required :attribute, "Attribute of the model" %> | ||
<%= partial.options.optional.yield o %> | ||
<% end %> |
24 changes: 24 additions & 0 deletions
24
...mes-light/app/views/showcase/previews/field_partials/attribute_partials/_address.html.erb
This file contains 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,24 @@ | ||
<%= render "showcase/previews/field_partials/attribute_partials/about_attribute_partials", showcase: showcase do |partial| %> | ||
<% partial.body do |object| %> | ||
<% object.address_value = Address.new( | ||
country_id: 233, | ||
address_one: "2800 East Observatory Road", | ||
city: "Los Angeles", | ||
region_id: 1416, | ||
postal_code: "90027" | ||
) | ||
%> | ||
<% showcase.sample "Multi-line" do %> | ||
<%= render 'shared/attributes/address', object: object, attribute: :address_value %> | ||
<% end %> | ||
<% showcase.sample "One-line" do %> | ||
<%= render 'shared/attributes/address', object: object, attribute: :address_value, one_line: true %> | ||
<% end %> | ||
<% end %> | ||
<% partial.options do |o| %> | ||
<% o.optional :one_line, "Render into a single line", type: "Boolean" %> | ||
<% end %> | ||
<% end %> |
This file contains 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
21 changes: 21 additions & 0 deletions
21
...themes-tailwind_css/app/views/themes/tailwind_css/fields/_dependent_fields_frame.html.erb
This file contains 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,21 @@ | ||
<% | ||
stimulus_controller = "dependent-fields-frame" | ||
html_options ||= {} | ||
html_options[:data] ||= {} | ||
html_options[:data][:controller] ||= "" | ||
html_options[:data][:controller] += " #{stimulus_controller}" | ||
html_options[:data][:action] ||= "" | ||
html_options[:data][:action] += " dependable:updated->#{stimulus_controller}#updateFrameFromDependableField turbo:frame-render->#{stimulus_controller}#finishFrameUpdate" | ||
html_options[:data]["#{stimulus_controller}-loading-class"] ||= "opacity-60" | ||
|
||
dependable_fields ||= [] | ||
%> | ||
<%= turbo_frame_tag id, **html_options do %> | ||
<% | ||
dependable_fields.each do |method| | ||
accept_query_string_override_for(form, method) | ||
end | ||
%> | ||
<%= yield stimulus_controller %> | ||
<% end %> |
Oops, something went wrong.