0

In rails, some forms get validated on client-side automatically, so that the form doesn't get submitted when inappropriate values are in the form fields. You get something likerails form validation

I want to fire a javascript event (reveal a spinning loader in this case) but only when this doesn't happen, and the form actually gets submitted.

At the moment I have

$(document).ready( function () {
  $('#new_import').on("submit", function () {
    $('#product_import_loading').slideDown();
  });
});

but this fires even when validation prevents submission.

What can I do?

1 Answer 1

2

I'm pretty sure there are no inherent jquery-ujs events regarding form validation, but you can easily use something like jQuery validation to do something only when the form passes client-side validation.

This would probably suit your needs (I don't have much experience with the plugin):

$("#new_import").on('submit', function() {
  if($(this).valid()) {
    // show your spinner
  }
  else {
    // do other stuff
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.