From 53e7a83e124b274f887d368fca7623bba6a6107c Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 1 Jun 2011 16:31:06 -0400 Subject: [PATCH] Minor corrections to TagCreation.js. Resolves issue #125. --- philo/admin/widgets.py | 2 +- philo/static/{admin => philo}/js/TagCreation.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) rename philo/static/{admin => philo}/js/TagCreation.js (91%) diff --git a/philo/admin/widgets.py b/philo/admin/widgets.py index 62a492b..c753850 100644 --- a/philo/admin/widgets.py +++ b/philo/admin/widgets.py @@ -52,7 +52,7 @@ class TagFilteredSelectMultiple(FilteredSelectMultiple): settings.ADMIN_MEDIA_PREFIX + "js/core.js", settings.ADMIN_MEDIA_PREFIX + "js/SelectBox.js", settings.ADMIN_MEDIA_PREFIX + "js/SelectFilter2.js", - settings.ADMIN_MEDIA_PREFIX + "js/TagCreation.js", + "philo/js/TagCreation.js", ) def render(self, name, value, attrs=None, choices=()): diff --git a/philo/static/admin/js/TagCreation.js b/philo/static/philo/js/TagCreation.js similarity index 91% rename from philo/static/admin/js/TagCreation.js rename to philo/static/philo/js/TagCreation.js index d08d41e..610a4f0 100644 --- a/philo/static/admin/js/TagCreation.js +++ b/philo/static/philo/js/TagCreation.js @@ -76,16 +76,23 @@ var tagCreation = window.tagCreation; tagCreation.toggleButton(id); addEvent(input, 'keyup', function() { tagCreation.toggleButton(id); - }) + }); addEvent(addLink, 'click', function(e) { e.preventDefault(); tagCreation.addTagFromSlug(addLink); + }); + // SelectFilter actually mistakenly allows submission on enter. We disallow it. + addEvent(input, 'keypress', function(e) { + if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { + e.preventDefault(); + } }) }, 'toggleButton': function(id) { var addLink = tagCreation.cache[id].addLink; var select = $(tagCreation.cache[id].select); - if (select[0].options.length == 0) { + var input = tagCreation.cache[id].input; + if (input.value != "") { if (addLink.style.display == 'none') { addLink.style.display = 'block'; select.height(select.height() - $(addLink).outerHeight(false)) -- 2.20.1