javascript - Ruby on Rails, when user not accepts terms show alert with jQuery -
in ruby on rails app have form looks this:
= simple_form_for @reservation |f| = f.input :terms, as: :boolean = f.submit t('reservation.next'), class: "btn btn-default pull-right" in model have virtual attribute terms:
validates :terms, acceptance: true, on: :create, allow_nil: false attr_accessor :terms now when user not take terms application redirect flash error. want when user not take regulation submit button disabled. there way jquery? in advance.
something should job. you'll need alter jquery selectors in illustration (#your_reservation_terms_checkbox , #your_submit_button) correctly match actual ids of elements.
= simple_form_for @reservation |f| = f.input :terms, as: :boolean = f.submit t('reservation.next'), class: "btn btn-default pull-right" :javascript $(document).ready(function(){ $('input#your_reservation_terms_checkbox').on('change', function(){ checked = $(this).is(':checked'); $('#your_submit_button').prop('disabled', !checked); $('.warning-message').remove() if(!checked){ $('#your_submit_button').before('<span class="warning-message">you must take terms</span>'); } }); }); javascript jquery ruby-on-rails ruby
No comments:
Post a Comment