exrezzo exrezzo - 5 months ago 34
Javascript Question

Prevent save button to submit form in Django admin

I wrote a control over some input in my admin form, which is executed on save buttons' click (I control a repetition of some inputs, but that's not important).

So, if this check fails, I alert a message, but I also need to avoid django admin to send this wrong request to the server. How can i do it in Javascript? (i'm using jQuery)

Answer

If you are using jQuery:

$( "form" ).submit(function( event ) {
  event.preventDefault();
  ...
});

http://api.jquery.com/event.preventdefault/

Comments