Change slug cleaning to only happen on blur, not every keypress - fixes #132

a854c03f44 improves the behaviour a lot, but it's
still fairly nasty for a text field to be rewriting text as you type it. It's
also unnecessary - you have to be pretty determined to submit the form without
triggering the blur event on the field, and if you do, all that happens is that
you fail server-side validation.
pull/190/head
Matt Westcott 2014-04-07 12:05:01 +01:00
rodzic 9bd91848e0
commit 626edda50d
1 zmienionych plików z 2 dodań i 14 usunięć

Wyświetl plik

@ -261,20 +261,8 @@ function initSlugAutoPopulate(){
}
function initSlugCleaning(){
$('#id_slug').on({
'blur': function(){
$(this).val(cleanForSlug($(this).val()));
},
'keyup': function(event){
var keyCode = ('which' in event) ? event.which : event.keyCode;
if (
(keyCode != 32) && // not spacebar
(keyCode != 8) && // not backspace
(keyCode != 46) && // not delete
((keyCode < 40) ) // non-character
) return ;
$(this).val(cleanForSlug($(this).val()));
}
$('#id_slug').blur(function(){
$(this).val(cleanForSlug($(this).val()));
});
}