simple_form
simple_form copied to clipboard
How to display hint for `simple_fields_for` ?
Hi, I created demo app.
https://simple-form-hint.herokuapp.com
In my project. a nested model's hint does not show in form. So, I reproduce that by simple app.
Access this link. https://simple-form-hint.herokuapp.com/accounts/1/edit
So, Account model's attributes has hints. (which is like hint!)
but, Account::Setting model's attr not shown.
this form was generated by simple_fields_for.
<%= simple_form_for(@account) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :active %>
</div>
<%= f.simple_fields_for :setting do |f| %>
<div class="form-inputs">
<%= f.input :enabled %>
<%= f.input :memo %>
</div>
<% end %>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
locale file is ... https://github.com/kntmrkm-public/simple_form_hint/blob/master/config/locales/simple_form.en.yml
I thought that locale file is wrong?
So, I created another model Account::Post.
https://simple-form-hint.herokuapp.com/accounts/1 https://simple-form-hint.herokuapp.com/account/posts/1/edit
It works. hint was shown. locale file is good.
That means I do not know how to show hint for simple_fields_for.
Sorry my English.
Thanks for the issue and sorry for the delay. Could you provide the code of the demo app? I'll take a look.
I took this for a ride and have noticed the following behavior:
simple_form_for and simple_fields_for behave differently when it comes to lookups because the object_model is different:
simple_form_for @account_setting
object_name is "account_setting"
simple_form_for @account
simple_fields_for :settings
object_name is "account[setting_attributes]"
So, when setting_attributes are present, setting is being looked up under account:
en:
simple_form:
hints:
account:
name: name for account hint!
active: boolean input for account hint!
setting:
memo: memo for account_setting hint!
enabled: boolean input for account_setting hint!
Whereas if it was just account_setting, then lookup is as follows:
en:
simple_form:
hints:
account_setting:
memo: memo for account_setting hint!
enabled: boolean input for account_setting hint!
simple_fields_for is for associations, so it looks logical to me that setting is being looked up under the model.
Perhaps worth adding an example to the README, @rafaelfranca? 😄
I came across this issue today. I usually assign labels of fields directly and active record attributes, and leave hints and some specific label under locale.simple_form.*. Usually I search by type and fill the attribute name or hint.
Nesting the key for records end up not so nice when the association is polymorphic.
So if the model is
class Model
belongs_to :details, polymorphic: true
end
class DetailsA
# lorem field
# ipsum field
end
class DetailsB
# lorem field
# dolor field
end
The resulting hint locale would need to be
en:
simple_form:
hints:
model:
details:
lorem: Lorem
ipsum: Ipsum
dolor: Dolor
So
- There is no way AFAIK to customize the lorem label for each of DetailsA and DetailsB.
- There is no easy to pic type information for the nested attribute.
Not blocking, but just clarifying some scenarios make me use simple form a lot and are lost when nested attributes are involved.
Maybe some fallback in hints and labels can be introduced that would use type information:
en:
simple_form:
hints:
model:
details:
lorem: Lorem
ipsum: Ipsum
dolor: Dolor
details_a:
lorem: Custom hint for DetailA
Although that would require an instance of the nested model in the association.