Skip to content

Commit dd4737e

Browse files
Display field hints on nested forms (#2804)
Currently field hints work on the `application/_form.html.erb`, but when a nested form is used, they are not displayed. This is basically copying those lines from the form partial, with the difference that we're using `f.object_name` instead.
1 parent 0cd5c67 commit dd4737e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/views/fields/has_one/_form.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ The form will be rendered as nested_from to parent relationship.
3030
<div class="field-unit field-unit--<%= attribute.html_class %>">
3131
<%= render_field attribute, f: has_one_f %>
3232
</div>
33+
<% hint_key = "administrate.field_hints.#{field.name}.#{attribute.name}" %>
34+
<% if I18n.exists?(hint_key) -%>
35+
<div class="field-unit__hint">
36+
<%= I18n.t(hint_key) %>
37+
</div>
38+
<% end -%>
3339
<% end %>
3440
</fieldset>
3541

spec/features/products_form_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,25 @@
107107
expect(page).to have_css("legend", text: custom_label)
108108
end
109109
end
110+
111+
it "displays hints on the has_one nested fields" do
112+
meta_description_hint = "A very meta description"
113+
product = create(:product)
114+
115+
translations = {
116+
administrate: {
117+
field_hints: {
118+
product_meta_tag: {
119+
meta_description: meta_description_hint
120+
}
121+
}
122+
}
123+
}
124+
125+
with_translations(:en, translations) do
126+
visit edit_admin_product_path(product)
127+
expect(page).to have_css(".field-unit__hint", text: meta_description_hint)
128+
end
129+
end
110130
end
111131
end

0 commit comments

Comments
 (0)