I have a Django form with a multi-select on it. I am using the multi.js library to modify the look & feel of the multi-select. I am also using the Django Bootstrap Modal Forms package to be able to add new options to my select list without leaving/refreshing the page.
Currently, when I add a new item via the modal form, it is added in the back-end, but the multi-select does not get updated from the JsonResponse.
If I remove the code that applies the multi.js functionality to the multi-select, then it is refreshed properly when the modal window closes.
As per this issue in GitHub, I thought I might just have to trigger the change function for the select element, but that doesn't seem to work for me. I've tried adding $select.trigger( 'change' );
to the last line of the createQuestionModalForm
function, but even though that is hit in the debugger after submitting the modal, it doesn't seem to do anything.
Here's the relevant JS:
$('#id_questions').multi();
$(function () {
function createQuestionModalForm() {
$("#addQuestion").modalForm({
formURL: "{% url 'question_create' %}",
asyncUpdate: true,
asyncSettings: {
closeOnSubmit: true,
successMessage: "test",
dataUrl: "/projects/question_update",
dataElementId: "#id_questions",
dataKey: "question_select",
addModalFormFunction: createQuestionModalForm
}
});
}
createQuestionModalForm();
});
Are there any other tricks I can be using to force the multi.js plugin to properly display the updated node when the AJAX update is complete?