Removed 'return false' in favor of preventDefault. #24

Merged
merged 1 commit into from May 18, 2012

7 participants

@marcneuwirth

Using 'return false' makes it very difficult to add additional event handlers to the add button because it prevent the events from bubbling up; preventDefault appears to be the desired behavior.

Also, other various js fixes like === instead of ==, missing parseInt radix, and missing semi colons

https://code.djangoproject.com/ticket/18241

@adrianholovaty
Django member

Hey, this is looking good. I have one question, though -- should the preventDefault calls perhaps be at the start of the event handler instead of the end? That way, if there's a runtime error in the handler, the link won't get followed (even though its href is "#").

See the Stack Overflow answer by Jeff Poulton here for a better explanation: http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false

Worth changing?

@marcneuwirth

Good idea

@eduardocereto

Note that internet explorer 8- doesn't support preventDefault. So you probably want to do this instead:

if (e.preventDefault) { 
    e.preventDefault(); 
} else {
    e.returnValue = false;
}
@mlavin

IE doesn't natively support e.preventDefault but this is will work inside a jQuery event handler because jQuery.Event defines preventDefault https://github.com/jquery/jquery/blob/1.4.2/src/event.js#L566

@alex
Django member

Looks good to me, Adrian, are you good with this?

@adrianholovaty
Django member

This looks good -- thanks, guys. I'd like us to start squashing our pull requests, though, so that I end up making only one commit to the Django master repository. @marcneuwirth -- can you squash your commits into one?

@adrianholovaty adrianholovaty merged commit 04785d2 into django:master May 18, 2012
@adrianholovaty
Django member

Thank you!

@jezdez
Django member

The minified version needs to be updated, too.

@jphalip
Django member

The minified version was updated in fadcc6d.

@jezdez
Django member

Odd, pretty sure I updated the files, at the time, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment