Closed realnot closed 2 months ago
@realnot
<script>
$("#id_birthday_country").change(function () {
var url = $("#resumeForm").attr("data-provinces-url");
var countryId = $(this).val();
$.ajax({
url: url,
data: {
'country': countryId
},
success: function (data) {
const element = document.getElementById('id_birthday_province');
const choices = new Choices(element);
choices.setChoices([
{ value: 'One', label: 'Label One', disabled: true },
{ value: 'Two', label: 'Label Two', selected: true },
{ value: 'Three', label: 'Label Three' },
]);
}
});
});
</script>
Try to check with the above code.
You're getting this error because you are making a new choices on every change of the country field. This line const choices = new Choices(element)
should be outside of the change handler so it only gets executed once.
I have an empty dropdown that I need to populate with choices retrieved from server. This is the DOM
and this is the script
What I'm doing wrong here?