I have question regarding predefining item on the list in bootstrap tags input. For example. var city_list = ['Sumatra', 'Jawa', 'Sulawesi'] var city_choosen = ['Sumatra']
When the page open, I would like to predefine the input with apple, but in documentation the method .add cause duplication on 'Sumatra'. I want to define it from the existing list, not add a new one.
Thank you.
var tagInput = $('#inputCity');
tagInput.tagsinput({
itemValue: 'id',
itemText: 'name',
typeaheadjs: {
autoselect: true,
name: 'cities',
displayKey: 'name',
source: cities.ttAdapter()
}
})
tagInput.tagsinput('add', {"id": 2, 'name': "Sumatra Utara"});
I found my error's solution. In my php code, I put quote inside the id value, so it will get duplicate, for example: 2 and '2'.