Skip to content

Commit a95c23b

Browse files
author
AMJones
committed
Corrects issue with searchField plugin that caused the callback to be fired multiple times with the same value.
1 parent a653e4b commit a95c23b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"css"
1111
],
1212
"homepage": "https://www.github.com/strapless/base",
13-
"version": "1.1.7",
13+
"version": "1.1.8",
1414
"authors": [
1515
{
1616
"name": "Aaron M Jones",

js/search-field.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @returns {jQuery}
66
*/
7-
(function($) {
7+
;(function($) {
88

99
$.searchField = function(el, options) {
1010

@@ -34,6 +34,7 @@
3434

3535
plugin.settings = $.extend({}, defaults, options);
3636
plugin.currentValue = '';
37+
plugin.onChangeInterval = {};
3738

3839
// Remove autocomplete attribute to prevent native suggestions
3940
$input.attr('autocomplete', 'off');
@@ -46,8 +47,8 @@
4647
$input
4748
.on('keyup', function (e) { plugin.onKeyUp(e); })
4849
.on('keydown', function (e) { plugin.onKeyDown(e); })
49-
.on('blur', function () { plugin.doCallback(); })
50-
.on('change', function () { plugin.doCallback(); })
50+
.on('blur', function () { if( plugin.currentValue !== $input.val() ) { plugin.doCallback(); } })
51+
.on('change', function () { if( plugin.currentValue !== $input.val() ) { plugin.doCallback(); } })
5152
;
5253
};
5354

@@ -99,9 +100,12 @@
99100
};
100101

101102
plugin.isSpecialKey = function(keyPressed) {
103+
var retval = false;
102104
$.each( keys, function( key, value ) {
103-
return (value === keyPressed);
105+
retval = retval || (value === keyPressed);
104106
});
107+
108+
return retval;
105109
};
106110

107111
plugin.doCallback = function() {

0 commit comments

Comments
 (0)