Extract merge_translatable_field_options helper method
This commit is contained in:
@@ -11,6 +11,19 @@ module TranslatableFormHelper
|
||||
yield(f)
|
||||
end
|
||||
end
|
||||
|
||||
def merge_translatable_field_options(options, locale)
|
||||
options.merge(
|
||||
class: (options.fetch(:class, "") + " js-globalize-attribute"),
|
||||
style: display_translation?(locale),
|
||||
data: options.fetch(:data, {}).merge(locale: locale),
|
||||
label_options: {
|
||||
class: (options.fetch(:class, "") + " js-globalize-attribute"),
|
||||
style: display_translation?(locale),
|
||||
data: (options.dig(:label_options, :data) || {}) .merge(locale: locale)
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder
|
||||
@@ -28,17 +41,7 @@ class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder
|
||||
@template.capture do
|
||||
@object.globalize_locales.each do |locale|
|
||||
Globalize.with_locale(locale) do
|
||||
final_options = options.merge(
|
||||
class: (options.fetch(:class, "") + " js-globalize-attribute"),
|
||||
style: @template.display_translation?(locale),
|
||||
data: options.fetch(:data, {}).merge(locale: locale),
|
||||
label_options: {
|
||||
class: (options.fetch(:class, "") + " js-globalize-attribute"),
|
||||
style: @template.display_translation?(locale),
|
||||
data: (options.dig(:label_options, :data) || {}) .merge(locale: locale)
|
||||
}
|
||||
)
|
||||
|
||||
final_options = @template.merge_translatable_field_options(options, locale)
|
||||
@template.concat send(field_type, "#{method}_#{locale}", final_options)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,9 +11,5 @@
|
||||
<%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]",
|
||||
i18n_content_translation ||
|
||||
t(content.key, locale: locale),
|
||||
{ rows: 5,
|
||||
class: "js-globalize-attribute",
|
||||
style: display_translation?(locale),
|
||||
data: { locale: locale }
|
||||
} %>
|
||||
merge_translatable_field_options({rows: 5}, locale) %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user