Something Wrong when wanner get input value using $('input').taginput('items')
imfht opened this issue · comments
$('input').taginput('items') returns like below. Could someone give me a hand?
<script src="https://cdn.bootcss.com/typeahead.js/0.11.1/typeahead.jquery.min.js"></script>
<script src="https://cdn.bootcss.com/typeahead.js/0.11.1/bloodhound.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.js"></script>
<script>
var citynames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: '/tags',
filter: function (list) {
return $.map(list, function (cityname) {
return {name: cityname};
});
}
}
});
citynames.initialize();
var input_tag = $('input').tagsinput({
typeaheadjs: {
name: 'citynames',
displayKey: 'name',
valueKey: 'name',
maxChars: 10,
source: citynames.ttAdapter()
}
});
function submit_tag() {
var csrf_token = "xxxx"
$.ajax({
url: '/delete_domain',
type: 'post',
data: {domain_id: domain, csrf_token: csrf_token},
success: function (response) {
if (response.success == 0) {
alert('删除失败,原因:' + response.data);
}
else {
alert('删除成功');
location.reload();
}
},
error: function (response) {
alert(response);
}
})
}
</script>
the input form like
<form>
<input type="text" value="Amsterdam,Washington" data-role="tagsinput" name="tags"/>
<button type="button" class="btn-sm btn-primary" style="float: right" onclick="">
提交
</button>
</form>
I've googled it but found no result. Could some one help me ?
Stupid me. Solved.
Because of typehead, there is another input tag named tt-input and $('input').taginput('items') select the tt-input.
Solved!