From f70ef3ff2fcfe8f0f1992c5ec72b3569da1cbe7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 10 Oct 2018 14:08:35 +0200 Subject: [PATCH] Fix question options translations not being saved If we enabled the locale and then added an option, the "add option" link added the partial which was generated before enabling the translation, and so it generated a field where the translation was disabled. Enabling the translation after inserting each field solves the issue. --- app/assets/javascripts/globalize.js.coffee | 11 +++++++++++ app/views/admin/legislation/questions/_form.html.erb | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/globalize.js.coffee b/app/assets/javascripts/globalize.js.coffee index 81e336ad6..06b1722f5 100644 --- a/app/assets/javascripts/globalize.js.coffee +++ b/app/assets/javascripts/globalize.js.coffee @@ -39,6 +39,12 @@ App.Globalize = disable_locale: (locale) -> App.Globalize.destroy_locale_field(locale).val(true) + enabled_locales: -> + $.map( + $(".js-globalize-locale-link:visible"), + (element) -> $(element).data("locale") + ) + destroy_locale_field: (locale) -> $(".destroy_locale[data-locale=" + locale + "]") @@ -61,3 +67,8 @@ App.Globalize = $(this).hide() App.Globalize.remove_language(locale) + $(".add_fields_container").on "cocoon:after-insert", -> + $.each( + App.Globalize.enabled_locales(), + (index, locale) -> App.Globalize.enable_locale(locale) + ) diff --git a/app/views/admin/legislation/questions/_form.html.erb b/app/views/admin/legislation/questions/_form.html.erb index dc5efb734..d9db3419d 100644 --- a/app/views/admin/legislation/questions/_form.html.erb +++ b/app/views/admin/legislation/questions/_form.html.erb @@ -36,8 +36,10 @@ <% end %>
- <%= link_to_add_association t("admin.legislation.questions.form.add_option"), +
+ <%= link_to_add_association t("admin.legislation.questions.form.add_option"), f, :question_options, class: "button hollow" %> +