diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index 66b33b47..61aaeb1c 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -39,10 +39,21 @@ $(document).on('turbolinks:load', function() { } }; + const hidePaymentInfoIfNeeded = function(value) { + const val = parseInt(value); + if (window.freeTickets && window.freeTickets.includes(val)) { + $("#payment-info").hide(); + } else { + $("#payment-info").show(); + } + }; + $("#registration_access_level").on('change', function() { - return hideCommentFieldIfNeeded($(this).val()); + hidePaymentInfoIfNeeded($(this).val()); + hideCommentFieldIfNeeded($(this).val()); }); - return hideCommentFieldIfNeeded($("#registration_access_level").val()); + hidePaymentInfoIfNeeded($("#registration_access_level").val()); + hideCommentFieldIfNeeded($("#registration_access_level").val()); }); diff --git a/app/views/registrations/_form.html.erb b/app/views/registrations/_form.html.erb index 831aaeb4..6079fd3e 100644 --- a/app/views/registrations/_form.html.erb +++ b/app/views/registrations/_form.html.erb @@ -12,12 +12,13 @@ <%= form_text_area f, :comment %> <%= javascript_tag do %> window.ticketsWithComments = <%= @event.access_levels.find_all(&:has_comment).map(&:id).to_json %> + window.freeTickets = <%= @event.access_levels.where(price: 0).map(&:id).to_json %> <% end %> <%= f.submit "Register", class: 'btn btn-group btn-primary' %> <% end %>
-