Skip to content
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

How to display hint for simple_fields_for ? #1358

Open
kntmrkm opened this issue Feb 13, 2016 · 3 comments
Open

How to display hint for simple_fields_for ? #1358

kntmrkm opened this issue Feb 13, 2016 · 3 comments

Comments

@kntmrkm
Copy link

kntmrkm commented Feb 13, 2016

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.

@rafaelfranca
Copy link
Collaborator

Thanks for the issue and sorry for the delay. Could you provide the code of the demo app? I'll take a look.

@petrgazarov
Copy link
Contributor

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? 😄

@bcardiff
Copy link

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

  1. There is no way AFAIK to customize the lorem label for each of DetailsA and DetailsB.
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants