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

Add support for changing form field labels. #755

Closed
wants to merge 1 commit into from

Conversation

dts
Copy link

@dts dts commented Feb 22, 2017

I found myself wanting to change the labels associated with form fields, which are often good for programmers and maybe not so good for administrators. The syntax looks like so:

subject: Field::String(label: "Model or Vehicle"),

Copy link
Contributor

@jcmorrow jcmorrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an interesting idea. What do you think about writing specs for it?

@@ -27,6 +27,10 @@ def self.permitted_attribute(attr)
attr
end

def label
options[:label] || attribute.to_s.humanize.capitalize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we allowed the overriding but didn't attempt to figure out the label name from the attribute if the option was missing and instead just returned nil? Then we can continue to let the form builder handle the unspecified case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that would work as well - I don't think there's any reason to do it this way (other than that it is explicit).

@dts
Copy link
Author

dts commented Mar 14, 2017

What kinds of specs would you think would be useful for this change?

@jondkinney
Copy link

I'd like this ability, too. However, I'd prefer if we used the existing i18n paradigm so that if we specify it in en.yml for a field to override a table header, that same override would get applied to the form field. Like this PR, it's a trivial change and I've done it in a fork that I'm maintaining. Happy to provide the code if that's helpful, but it's just a copy and paste of the i18n query from the collection partial's table header lookup.

@cpytel
Copy link
Member

cpytel commented Sep 7, 2018

Thank you for the help. Since this PR was suggested, we've added the ability to customize the field labels with I18n. You can find the documentation for this at https://github.com/thoughtbot/administrate/blob/master/docs/customizing_dashboards.md#defining-labels

@cpytel cpytel closed this Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants