Skip to content

Commit

Permalink
Add option to search on specific keycode (#37)
Browse files Browse the repository at this point in the history
* Add keycode in options

trigger only search when keycode specified, for example { keyCode : 13 } for enter  event

* Add keycode in options

trigger only search when keycode specified.
for example using enter event :

$('input#search').quicksearch('table tbody tr', {
	'delay': 100,
	'selector': 'th',
	'stripeRows': ['odd', 'even'],
	'loader': 'span.loading',
	'noResults': 'tr#noresults',
	'bind': 'keyup keydown',
	'minValLength': 2,
	'removeDiacritics': true,
        'keyCode ': 13,
	'onBefore': function () {
		console.log('on before');
	},
	'onAfter': function () {
		console.log('on after');
	},
	'onValTooSmall': function (val) {
		console.log('value ' + val + ' is too small');
	},
	'show': function () {
		$(this).addClass('show');
	},
	'hide': function () {
		$(this).removeClass('show');
	}
	'prepareQuery': function (val) {
		return new RegExp(val, "i");
	},
	'testQuery': function (query, txt, _row) {
		return query.test(txt);
	}
});
  • Loading branch information
nckenn authored and nitriques committed Aug 15, 2017
1 parent 9c6663f commit 506b208
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/jquery.quicksearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
caseSensitive: false,
noResults: '',
matchedResultsCount: 0,
keyCode : false,
bind: 'keyup search input',
resetBind: 'reset',
removeDiacritics: false,
Expand Down Expand Up @@ -315,10 +316,19 @@
this.loader(false);

return this.each(function () {
$(this).on(options.bind, function () {
val = $(this).val();
self.trigger();
$(this).on(options.bind, function (e) {
if (options.keyCode) {
var keycode = e.keyCode || e.which;
if (keycode === options.keyCode) {
val = $(this).val();
self.trigger();
}
} else {
val = $(this).val();
self.trigger();
}
});

$(this).on(options.resetBind, function () {
val = '';
self.reset();
Expand Down

0 comments on commit 506b208

Please sign in to comment.