diff mbox

[46/49] filter: Tweak the autocompletion behaviour on <Enter>

Message ID 1443708774-26996-47-git-send-email-damien.lespiau@intel.com
State Accepted
Headers show

Commit Message

Damien Lespiau Oct. 1, 2015, 2:12 p.m. UTC
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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff mbox

Patch

diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html
index 6ab8108..1af943b 100644
--- a/patchwork/templates/patchwork/filters.html
+++ b/patchwork/templates/patchwork/filters.html
@@ -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;' +