Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preventDuplicates when allowing custom tags #1

Merged
merged 7 commits into from Oct 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.project
_site
_layouts
.DS_Store
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -9,4 +9,12 @@ Documentation, Features and Demos
---------------------------------
Full details and documentation can be found on the project page here:

<http://loopj.com/jquery-tokeninput/>
<http://loopj.com/jquery-tokeninput/>


Changes in this fork:
---------------------------------

* User can add custom tags.
* Fixed preventDuplicates bevahiour after allowing user to create his custom tags
* More user-friendly (in my opinion) behaviour: when input losses focus, it consider user input that was entered but not added as a tag(by clicking tab/enter/typing comma etc)as a tag. So when the user uses mouse to navigate the form inputs, the data he entered to 'tokeninput'will be submitted when he submitts the form
21 changes: 17 additions & 4 deletions src/jquery.tokeninput.js
Expand Up @@ -197,9 +197,22 @@ $.TokenList = function (input, url_or_data, settings) {
show_dropdown_hint();
}
})
.blur(function () {
hide_dropdown();
// $(this).val("");
.blur(function (){
hide_dropdown();
/**
* When input looses focus, and it contains not yet added tags(for ex no enter/tab was pressed)
* it should act the same way as it the enter/tab was pressed.
* It prevents from not containing some data entered by the user
* when the form with the input is submitted, if he for example moves from input
* to input with a mouse not the tab
*/
if( settings.allowNewItems && $(this).val()){
var item = {};
item[settings.tokenValue] = settings.allowNewItemsPrefix+$(this).val();
item[settings.propertyToSearch] = $(this).val();

add_token(item);
}
})
.bind("keyup keydown blur update", resize_input)
.keydown(function (event) {
Expand Down Expand Up @@ -505,7 +518,7 @@ $.TokenList = function (input, url_or_data, settings) {
token_list.children().each(function () {
var existing_token = $(this);
var existing_data = $.data(existing_token.get(0), "tokeninput");
if(existing_data && existing_data.id === item.id) {
if(existing_data && existing_data[settings.tokenValue] === item[settings.tokenValue]) {
found_existing_token = existing_token;
return false;
}
Expand Down