Minor corrections to TagCreation.js. Resolves issue #125.
authorStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 1 Jun 2011 20:31:06 +0000 (16:31 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 1 Jun 2011 20:31:06 +0000 (16:31 -0400)
philo/admin/widgets.py
philo/static/philo/js/TagCreation.js [moved from philo/static/admin/js/TagCreation.js with 91% similarity]

index 62a492b..c753850 100644 (file)
@@ -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=()):
similarity index 91%
rename from philo/static/admin/js/TagCreation.js
rename to philo/static/philo/js/TagCreation.js
index d08d41e..610a4f0 100644 (file)
@@ -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))