-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Custom labels for fields #451
Comments
+1 |
You can do this via localization. config/locales/en.yml
|
I have tried but does not work 😕. Do you have any project where you have did it to share? |
Problem: There was uncertainty about how to create custom labels for fields. In #451, it was suggested that we could use I18n translations to solve the problem. If we accept that as the standard way to set custom labels, we should have a test for it. Solution: - Add a test to verify that labels can be customized through I18n. - Add documentation about how to customize labels To Do: - Update view code so the same translation definition applies on the show and collection pages, in addition to the form page.
Problem: There was uncertainty about how to create custom labels for fields. In #451, it was suggested that we could use I18n translations to solve the problem. If we accept that as the standard way to set custom labels, we should have a test for it. Solution: - Add a test to verify that labels can be customized through I18n. - Add documentation about how to customize labels To Do: - Update view code so the same translation definition applies on the show and collection pages, in addition to the form page.
Sorry for the late. This solution works only on normal attributes but on relations doesn't work:
Here, the "nombre_documento" is a string attribute of control1 and It works. But "registro1s" is a relation, because control1 has many registro1s and it doesn't work. Any solution for this? |
I am trying this but it does not work. Do I need to create an administrate.en.yml file inside locales or can I just add it to my en.yml file ? |
Just in the en.yml , make sure you are not using i18n on your config/application.rb |
Ok, In my en.yml file I added this. (school is my model and tuition fee is the attribute )
And my dashboard is like this
Is that all I need to make it work ? I am trying to customize the label of the tuition fee attribute. |
Have you tried with only "Field::Number" ? maybe the kind of attribute is the key. |
It is only working on the form page but it is not working for the show page or index page. |
it could be, because the way this is working. I hope they can make a better option to customize labels. |
@Xosmond, @KatherineMuedas - ah, I didn't realize that you were talking about the index and show pages. I've updated #492 to work on all three types of pages. I'll try to get that merged in as soon as possible. |
@Graysonwright that would be great !! Thanks :) |
Problem: There was uncertainty about how to create custom labels for fields. In #451, it was suggested that we could use I18n translations to solve the problem. If we accept that as the standard way to set custom labels, we should have a test for it. Solution: - Add a test to verify that labels can be customized through I18n. - Add documentation about how to customize labels To Do: - Update view code so the same translation definition applies on the show and collection pages, in addition to the form page.
Closed by #492 |
The custom labels don't work in the forms as far as I can tell. They really can't either, because the forms render the attribute's key directly <%#
# HasMany Form Partial
This partial renders an input element for belongs_to relationships.
By default, the input is a collection select box
that displays all possible records to associate with.
The collection select box supports multiple inputs,
and is augmented with [Selectize].
## Local variables:
- `f`:
A Rails form generator, used to help create the appropriate input fields.
- `field`:
An instance of [Administrate::Field::HasMany][1].
Contains helper methods for displaying a collection select box.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
[Selectize]: http://brianreavis.github.io/selectize.js
%>
<div class="field-unit__label">
<%= f.label field.attribute_key, field.attribute %>
</div>
<div class="field-unit__field">
<%= f.select(field.attribute_key, nil, {}, multiple: true) do %>
<%= options_for_select(field.associated_resource_options, field.selected_options) %>
<% end %>
</div> However, if we add the same translate call that the collection partial does we can get what we need... <%#
# HasMany Form Partial
This partial renders an input element for belongs_to relationships.
By default, the input is a collection select box
that displays all possible records to associate with.
The collection select box supports multiple inputs,
and is augmented with [Selectize].
## Local variables:
- `f`:
A Rails form generator, used to help create the appropriate input fields.
- `field`:
An instance of [Administrate::Field::HasMany][1].
Contains helper methods for displaying a collection select box.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
[Selectize]: http://brianreavis.github.io/selectize.js
%>
<div class="field-unit__label">
<% label_text = t(
"helpers.label.#{f.object.class.name.underscore}.#{field.attribute_key}",
default: field.attribute.to_s,
).titleize %>
<%= f.label field.attribute_key, label_text %>
</div>
<div class="field-unit__field">
<%= f.select(field.attribute_key, nil, {}, multiple: true) do %>
<%= options_for_select(field.associated_resource_options, field.selected_options) %>
<% end %>
</div> I'll make a PR with this in the next week or two when I get time. Deploying with my custom fork for now. |
Here's an example for number (it's the same for string) <%#
# Number Form Partial
This partial renders an input element for number attributes.
By default, the input is a text field.
## Local variables:
- `f`:
A Rails form generator, used to help create the appropriate input fields.
- `field`:
An instance of [Administrate::Field::Number][1].
A wrapper around the number pulled from the database.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Number
%>
<div class="field-unit__label">
<% label_text = t(
"helpers.label.#{f.object.class.name.underscore}.#{field.attribute}",
default: field.attribute.to_s,
).titleize %>
<%= f.label label_text %>
</div>
<div class="field-unit__field">
<%= f.text_field field.attribute %>
</div> |
Hi, i have some models with short name fields and i want to change the label of some with other more verbose, how can i change the labels of some string fields? Thanks all.
The text was updated successfully, but these errors were encountered: