I'm new to jQuery selectize and I'm having issues in setting the value to a <select>
from database during editing the form. The <option>
is hardcoded in HTML.
HTML:
<select class="form-control" name="agentType" id="agentType">
<option value="">--Select Agent Type--</option>
<option value="Individual">Individual</option>
<option value="Partner">Partner</option>
</select>
Let's say the two values are saved in database viz(Individual & Partner).
And when I hit edit, I want one of Agent Type to be pre-selected and other one in the drop-down corresponding to value saved in database. Images shown Shown below:
Jquery:
$('#agentDataTable tbody').on( 'click', '.dataEdit', function () {
var data = agentDataTable.row( $(this).parents('tr') ).data();
$('#agentForm #agentName').val(data.agentName);
var $select = $('#agentForm #agentType').selectize();
var control = $select[0].selectize;
control.clear();
control.clearOptions();
control.addOption({text: data.agentType});
control.setValue(data.areaPincodeId, true);
});
But nothing shows at all in dropdown.
I've tried many other references but no answer matched my query as everyperson has their own ways.