diff --git a/app/assets/javascripts/admin/votation_types/fields.js b/app/assets/javascripts/admin/votation_types/fields.js index 85649e675..378d7474b 100644 --- a/app/assets/javascripts/admin/votation_types/fields.js +++ b/app/assets/javascripts/admin/votation_types/fields.js @@ -2,16 +2,18 @@ "use strict"; App.AdminVotationTypesFields = { adjustForm: function() { - if ($(this).val() === "unique") { - $(".max-votes").hide(); - $(".description-unique").show(); - $(".description-multiple").hide(); - $(".votation-type-max-votes").prop("disabled", true); - } else { + var select_field = $(this); + + $("[data-vote-type]").hide(0, function() { + $("[data-vote-type=" + select_field.val() + "]").show(); + }); + + if (select_field.val() === "multiple") { $(".max-votes").show(); - $(".description-unique").hide(); - $(".description-multiple").show(); $(".votation-type-max-votes").prop("disabled", false); + } else { + $(".max-votes").hide(); + $(".votation-type-max-votes").prop("disabled", true); } }, initialize: function() { diff --git a/app/components/admin/votation_types/fields_component.html.erb b/app/components/admin/votation_types/fields_component.html.erb index f55d74579..89183ee8b 100644 --- a/app/components/admin/votation_types/fields_component.html.erb +++ b/app/components/admin/votation_types/fields_component.html.erb @@ -4,12 +4,9 @@
- - <%= t("admin.polls.votation_type.unique_description") %> - - + <% descriptions.each do |vote_type, text| %> + <%= description_tag(vote_type, text) %> + <% end %>
diff --git a/app/components/admin/votation_types/fields_component.rb b/app/components/admin/votation_types/fields_component.rb index 6fe487397..a51a795a5 100644 --- a/app/components/admin/votation_types/fields_component.rb +++ b/app/components/admin/votation_types/fields_component.rb @@ -4,4 +4,17 @@ class Admin::VotationTypes::FieldsComponent < ApplicationComponent def initialize(form:) @form = form end + + private + + def descriptions + { + unique: t("admin.polls.votation_type.unique_description"), + multiple: t("admin.polls.votation_type.multiple_description") + } + end + + def description_tag(vote_type, text) + tag.span(text, data: { vote_type: vote_type }) + end end