diff mbox

[48/51] filter: Tweak the autocompletion behaviour on <Enter>

Message ID 1440440620-25937-49-git-send-email-damien.lespiau@intel.com
State Changes Requested
Headers show

Commit Message

Damien Lespiau Aug. 24, 2015, 6:23 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>
---
 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;' +