Bitwise
Bitwise

Reputation: 8451

Listening for submit of form NOT working

I'm trying to disable some buttons on submit of form but I can't seem to get the function to work with my setup. Here is my Javascript:

JS

$(document).ready(function() {
  $("form.upload-data-form").submit(function(e) {
    e.preventDefault();
    debugger;
  });
});

HTML

<%= form_for @changeset, upload_path(@conn, :create), [class: "upload-data-form", multipart: true], fn f -> %>

That ends up having this class .upload-data-form When I submit the form the debugger in my Javascript is not working. What am I doing wrong?

Upvotes: 1

Views: 35

Answers (2)

Rikin
Rikin

Reputation: 5473

$.noConflict();
jQuery( document ).ready(function( $ ) {
  $("form.upload-data-form").submit(function(e) {
    e.preventDefault();
    debugger;
  });
});

Upvotes: 1

Dij
Dij

Reputation: 9808

Event handlers are bound only to the currently selected elements; they must exist on the page at the time your code makes the call to event handlers. try delegating events on children of the document object

$(document).on("submit","form.upload-data-form", function(e) {
    e.preventDefault();
    debugger;
  });

Upvotes: 1

Related Questions