From 2eccb32d16610815694b7c7da74f1d8c64473446 Mon Sep 17 00:00:00 2001 From: BrentyMcFatty Date: Fri, 28 Oct 2022 01:52:28 +0200 Subject: [PATCH] trying to make solution less scuffed and bug-free --- app/assets/javascripts/registrations.js | 8 ++++---- app/views/registrations/_form.html.erb | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index b79bd529..9ac4ca91 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -40,8 +40,8 @@ $(document).on('turbolinks:load', function() { }; const hidePaymentInfoIfNeeded = function(value) { - - if (value.search("€") === -1) { + const val = parseInt(value); + if (window.freeTickets && (window.freeTickets.indexOf(val) !== -1)) { $("#payment-info").hide(); } else { $("#payment-info").show(); @@ -49,11 +49,11 @@ $(document).on('turbolinks:load', function() { }; $("#registration_access_level").on('change', function() { - hidePaymentInfoIfNeeded($("option:selected", this).text()); + hidePaymentInfoIfNeeded($(this).val()); return hideCommentFieldIfNeeded($(this).val()); }); - hidePaymentInfoIfNeeded($("#registration_access_level option:selected").text()); + hidePaymentInfoIfNeeded($("#registration_access_level").val()); return hideCommentFieldIfNeeded($("#registration_access_level").val()); }); diff --git a/app/views/registrations/_form.html.erb b/app/views/registrations/_form.html.erb index a82830c2..67dc876a 100644 --- a/app/views/registrations/_form.html.erb +++ b/app/views/registrations/_form.html.erb @@ -12,6 +12,9 @@ <%= 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.find_all{|_| :price == 0}.map(&:id).to_json %> + access_levels = <%= @event.access_levels.find_all{|_| true}.to_json %> + console.log("poop") <% end %> <%= f.submit "Register", class: 'btn btn-group btn-primary' %> <% end %>