From 626edda50d5fb0c23e658fbff8f0ca9ab51d3550 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Mon, 7 Apr 2014 12:05:01 +0100 Subject: [PATCH] Change slug cleaning to only happen on blur, not every keypress - fixes #132 a854c03f443083a1471dd066dece92527dbb7c7c 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. --- .../static/wagtailadmin/js/page-editor.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js index 63ffc7d29b..e34bbaf609 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js @@ -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())); }); }