on the page load i have a token input ie,
$('.txtWard').tokenInput(ward, {
theme: 'facebook',
allowCustomEntry: true,
preventDuplicates: true,
tokenDelimiter: '*',
searchingText: 'Searching...'
});
but the problem is when i click on another button i want to pre-populate items to this token input textbox.when i using the below code the textbox duplicating as another textbox.
$(document).ready(function () {
$('.txtWard').tokenInput(ward, {
theme: 'facebook',
allowCustomEntry: true,
preventDuplicates: true,
tokenDelimiter: '*',
searchingText: 'Searching...'
});
$('#btnGet').click(function () {
var prepopulateWards = new Array();
$.ajax({
type: "POST",
url: "FetchWard",
data: JSON.stringify({ patientNo: $('#txtPatientNo').val(), locale: 'en-US' }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
for (var j = 0; j < result.wards.length; j++) {
prepopulateWards.push({ id: result.wards[j].Code, name: result.wards[j].ward });
}
}
});
$('.txtWard').tokenInput(ward, {
theme: 'facebook',
allowCustomEntry: true,
preventDuplicates: true,
tokenDelimiter: '*',
searchingText: 'Searching...',
prePopulateFromValue: true,
prePopulate: prepopulateWards
});
});
});