admin管理员组文章数量:1336631
I am using jquery plugin Tokeninput. I need to prevent user from entering duplicate values, the Js code is as follows:
$(document).ready(function () {
// Configure Tags
$('#Tags').tokenInput(tagSource(),
{
prePopulate: selectedTags(),
theme: "facebook",
propertyToSearch: "Code",
preventDuplicates: true
});
function tagSource() {
var data = [];
@if (Model.SourceTags != null && Model.SourceTags.Count() > 0) {
<text>
data = @(Html.Raw(Model.SourceTags));
</text>
}
return data;
}
function selectedTags() {
var selectedData = [];
@if (Model.SelectedTags != null && Model.SelectedTags.Count() > 0) {
<text>
selectedData = @(Html.Raw(Model.SelectedTags));
</text>
}
return selectedData;
}
});
When I select the same item again, the existing item in the Input field is highlighted and nothing is added.
Also, when I select a different item, the first item is highlighted and nothing is added.
Any idea?
Thanks
I am using jquery plugin Tokeninput. I need to prevent user from entering duplicate values, the Js code is as follows:
$(document).ready(function () {
// Configure Tags
$('#Tags').tokenInput(tagSource(),
{
prePopulate: selectedTags(),
theme: "facebook",
propertyToSearch: "Code",
preventDuplicates: true
});
function tagSource() {
var data = [];
@if (Model.SourceTags != null && Model.SourceTags.Count() > 0) {
<text>
data = @(Html.Raw(Model.SourceTags));
</text>
}
return data;
}
function selectedTags() {
var selectedData = [];
@if (Model.SelectedTags != null && Model.SelectedTags.Count() > 0) {
<text>
selectedData = @(Html.Raw(Model.SelectedTags));
</text>
}
return selectedData;
}
});
When I select the same item again, the existing item in the Input field is highlighted and nothing is added.
Also, when I select a different item, the first item is highlighted and nothing is added.
Any idea?
Thanks
Share Improve this question asked Jun 18, 2012 at 13:39 BillBill 2,38210 gold badges58 silver badges102 bronze badges 1- i have the same issue have you found any solution ? – medBouzid Commented Jan 19, 2014 at 14:40
2 Answers
Reset to default 8In case you are still having this problem, I think I might know what is going on. TokenInput assumes that the "id" attribute of your data object is spelled exactly as "id" (note the lowercase). If your id attribute is spelled any differently, what you described will happen. For your reference, this happens in the add_token function (line 495 in the js file in v1.6.0 tokeninput.js).
the best way is to limit the drop down search list. by removing the selected items in the textfield.
"SELECT id, title from job_categories WHERE id NOT IN (".$member->category_id.") AND title LIKE '%%%".$this->input->get('q')."%%' ORDER BY id DESC LIMIT 10"
this query will remove the prePopulate values from the list being selected again
本文标签: javascripttokeninput jquery pluginpreventDuplicates not workingStack Overflow
版权声明:本文标题:javascript - tokeninput jquery plugin - preventDuplicates not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742336320a2455696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论