Created
July 23, 2015 10:24
-
-
Save gnepud/c302049b5d38da92f35e to your computer and use it in GitHub Desktop.
select2 3.5.2 + twitter Bloodhound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
var engine = new Bloodhound({ | |
local: [ | |
'Andorra', | |
'Unitéd Arab Emirates', | |
'Antarctica' | |
], | |
datumTokenizer: Bloodhound.tokenizers.whitespace, | |
queryTokenizer: Bloodhound.tokenizers.whitespace, | |
}); | |
engine.initialize(); | |
var target = ".srchtarget-CTRYID"; | |
$(target).select2({ | |
placeholder: "select a country", | |
quietMillis:300, | |
query: function (query) { | |
engine.search(query.term, function(resultArr){ | |
var r = []; | |
for(var i in resultArr){ | |
r.push({id: i, text: resultArr[i]}); | |
} | |
query.callback({results: r}); | |
}); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.2/select2.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.2/select2.js"></script> | |
</head> | |
<body> | |
<input data-placeholder="Select Country" class="srchtarget-CTRYID" id="header-CTRYID" name="header[CTRYID]" data-label="Country" type="text"/> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working in my local