]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
filter: Tweak the autocompletion behaviour on <Enter>
authorDamien Lespiau <damien.lespiau@intel.com>
Mon, 24 Aug 2015 16:27:49 +0000 (17:27 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Thu, 5 Nov 2015 03:56:26 +0000 (03:56 +0000)
No patch has landed yet and we've already had feedback from users (which
is a good thing!) that didn't want to lose the "quick" submitter search
by just typing a string and pressing <Enter> without having to wait for
the autocompletion to finish.

This will also make <Enter> do something useful for input strings that
have fewer than 4 characters, the autocompletion query only triggers
after that.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Acked-by: Stephen Finucane <stephen.finucane@intel.com>
patchwork/templates/patchwork/filters.html

index 6ab8108b527fb00e9b6d52b35719bd1e3c65eb86..1af943b9ebe1b7358378b45e31227e12d7de6411 100644 (file)
@@ -20,13 +20,36 @@ function filter_click()
 
 }
 
+Selectize.define('enter_key_submit', function (options) {
+    var self = this;
+
+    this.onKeyDown = (function (e) {
+        var original = self.onKeyDown;
+
+        return function (e) {
+            original.apply(this, arguments);
+
+            if (e.keyCode === 13 && this.$control_input.val() != '' )
+                self.trigger('submit');
+        };
+    })();
+});
+
 $(document).ready(function() {
     $('#submitter_input').selectize({
         valueField: 'pk',
         labelField: 'name',
         searchField: ['name', 'email'],
+        plugins: ['enter_key_submit'],
         maxItems: 1,
         persist: false,
+        onInitialize: function() {
+            this.on('submit', function() {
+                if (!this.items.length)
+                    this.$input.val(this.lastValue);
+                this.$input.closest('form').submit();
+            }, this);
+        },
         render: {
             option: function(item, escape) {
                 return '<div>' + escape(item.name) + ' &lt;' +