Skip to content

Commit

Permalink
Closes #112. Added parameter hideOnEmptyPhrase
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelczak authored and pawelczak committed Oct 26, 2015
1 parent da30a30 commit 43b97d6
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 41 deletions.
12 changes: 3 additions & 9 deletions demo/example_theme_square.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,24 @@ <h1>EasyAutocomplete - css themes</h1>

getValue: "name",

minCharNumber: 0,

list: {
match: {
enabled: true
},
maxNumberOfElements: 8,

onClickEvent: function() {
$("#square").change();
}
hideOnEmptyPhrase: true
},



theme: "square"

};

$("#square").easyAutocomplete(options);


$("#square").change(function() {
console.log($(this).val());
});

</script>

</body>
Expand Down
2 changes: 1 addition & 1 deletion dist/easy-autocomplete.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* jQuery plugin for autocompletion
*
* @author Łukasz Pawełczak (http://github.com/pawelczak)
* @version 1.1.6
* @version 1.2.0
* Copyright MIT License: https://github.com/pawelczak/easy-autocomplete/blob/master/LICENSE.txt
*/

Expand Down
2 changes: 1 addition & 1 deletion dist/easy-autocomplete.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/easy-autocomplete.themes.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* jQuery plugin for autocompletion
*
* @author Łukasz Pawełczak (http://github.com/pawelczak)
* @version 1.1.6
* @version 1.2.0
* Copyright MIT License: https://github.com/pawelczak/easy-autocomplete/blob/master/LICENSE.txt
*/

Expand Down
2 changes: 1 addition & 1 deletion dist/easy-autocomplete.themes.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions dist/jquery.easy-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* jQuery plugin for autocompletion
*
* @author Łukasz Pawełczak (http://github.com/pawelczak)
* @version 1.1.6
* @version 1.2.0
* Copyright MIT License: https://github.com/pawelczak/easy-autocomplete/blob/master/LICENSE.txt
*/

Expand Down Expand Up @@ -36,7 +36,6 @@ var EasyAutocomplete = (function(scope){

matchResponseProperty: false,


list: {
sort: {
enabled: false,
Expand All @@ -55,6 +54,8 @@ var EasyAutocomplete = (function(scope){

maxNumberOfElements: 6,

hideOnEmptyPhrase: true,

match: {
enabled: false,
caseSensitive: false,
Expand Down Expand Up @@ -1228,17 +1229,23 @@ var EasyAutocomplete = (function(scope) {
default:

if (event.keyCode > 40 || event.keyCode === 8) {
loadData();

var inputPhrase = $field.val();

if (!(config.get("list").hideOnEmptyPhrase === true && event.keyCode === 8 && inputPhrase === "")) {
loadData(inputPhrase);
} else {
hideContainer();
}

}


break;
}


function loadData() {

var inputPhrase = $field.val();
function loadData(inputPhrase) {


if (inputPhrase.length < config.get("minCharNumber")) {
Expand Down Expand Up @@ -1361,15 +1368,15 @@ var EasyAutocomplete = (function(scope) {
})
.keydown(function(event) {

if (event.keyCode === 13 && selectedElement > -1) {
if (event.keyCode === 13 && selectedElement > -1) {

$field.val(config.get("getValue")(elementsList[selectedElement]));
selectedElement = -1;
hideContainer();
$field.val(config.get("getValue")(elementsList[selectedElement]));
selectedElement = -1;
hideContainer();

event.preventDefault();
}
});
event.preventDefault();
}
});
}

function bindKeypress() {
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.easy-autocomplete.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var EasyAutocomplete = (function(scope){

matchResponseProperty: false,


list: {
sort: {
enabled: false,
Expand All @@ -48,6 +47,8 @@ var EasyAutocomplete = (function(scope){

maxNumberOfElements: 6,

hideOnEmptyPhrase: true,

match: {
enabled: false,
caseSensitive: false,
Expand Down
30 changes: 18 additions & 12 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,23 @@ var EasyAutocomplete = (function(scope) {
default:

if (event.keyCode > 40 || event.keyCode === 8) {
loadData();

var inputPhrase = $field.val();

if (!(config.get("list").hideOnEmptyPhrase === true && event.keyCode === 8 && inputPhrase === "")) {
loadData(inputPhrase);
} else {
hideContainer();
}

}


break;
}


function loadData() {

var inputPhrase = $field.val();
function loadData(inputPhrase) {


if (inputPhrase.length < config.get("minCharNumber")) {
Expand Down Expand Up @@ -572,17 +578,17 @@ var EasyAutocomplete = (function(scope) {
})
.keydown(function(event) {

if (event.keyCode === 13 && selectedElement > -1) {
if (event.keyCode === 13 && selectedElement > -1) {

//enter
//enter

$field.val(config.get("getValue")(elementsList[selectedElement]));
selectedElement = -1;
hideContainer();
$field.val(config.get("getValue")(elementsList[selectedElement]));
selectedElement = -1;
hideContainer();

event.preventDefault();
}
});
event.preventDefault();
}
});
}

function bindKeypress() {
Expand Down
111 changes: 111 additions & 0 deletions test/core/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,114 @@ QUnit.test("Minimal number of characters in input phrase - true", function( asse

});



QUnit.test("List, hideOnEmptyPhrase - false ", function( assert ) {
expect(1);

//given
var completerOne = new EasyAutocomplete.main($("#inputOne"), {url: "resources/colors_string.json",

list: {
onLoadEvent: function() {
assertList();
},

hideOnEmptyPhrase: false
}

});


//execute

completerOne.init();

var e = $.Event('keyup');
e.keyCode = 8; //backspace
$("#inputOne").val("").trigger(e);

QUnit.stop();

//assert

function assertList() {
var elements = $("#inputOne").next().find("ul li");

assert.equal(3, elements.length, "Response size");

QUnit.start();
}
});

QUnit.test("List, hideOnEmptyPhrase - true - empty input", function( assert ) {
expect(1);

//given
var completerOne = new EasyAutocomplete.main($("#inputOne"), {url: "resources/colors_string.json",

list: {

hideOnEmptyPhrase: true
}

});


//execute

completerOne.init();

var e = $.Event('keyup');
e.keyCode = 8; //backspace
$("#inputOne").val("").trigger(e);


//assert
var elements = $("#inputOne").next().find("ul li");

assert.equal(0, elements.length, "Response size");


});


QUnit.test("List, hideOnEmptyPhrase - true - not empty input", function( assert ) {
expect(1);

//given
var completerOne = new EasyAutocomplete.main($("#inputOne"), {url: "resources/colors_string.json",

list: {
onLoadEvent: function() {
assertList();
},

hideOnEmptyPhrase: true
}

});


//execute

completerOne.init();

var e = $.Event('keyup');
e.keyCode = 8; //backspace
$("#inputOne").val("aaaa").trigger(e);

QUnit.stop();

//assert

function assertList() {
var elements = $("#inputOne").next().find("ul li");

assert.equal(3, elements.length, "Response size");

QUnit.start();
}


});

0 comments on commit 43b97d6

Please sign in to comment.