From: Damien Lespiau Date: Mon, 24 Aug 2015 16:27:49 +0000 (+0100) Subject: filter: Tweak the autocompletion behaviour on X-Git-Tag: v1.1.0~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34ca190e83a0075d28793744e904cfb450e5bf2a;p=thirdparty%2Fpatchwork.git filter: Tweak the autocompletion behaviour on 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 without having to wait for the autocompletion to finish. This will also make do something useful for input strings that have fewer than 4 characters, the autocompletion query only triggers after that. Signed-off-by: Damien Lespiau Acked-by: Stephen Finucane --- diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html index 6ab8108b..1af943b9 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 '
' + escape(item.name) + ' <' +