-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resetting the form clears the list of choices #1053
Comments
I'm experiencing the same issue... how can we handle this scenario? |
Having the same issue. Is there a fix for this? |
The same issue when I clear form inputs. Still no fix? |
Ran into the same problem. I got an idea from issue #1023. My band-aid is to add an addEventListener() for the form reset. It still allows the form normal reset process to work. document.addEventListener('DOMContentLoaded', function () {
const choicejsOptions = {
allowHTML: false,
removeItemButton: true,
searchEnabled: true,
searchChoices: true,
searchFields: ['label', 'value'],
placeholder: true,
};
const selectList = new Choices('.js-choice__SelectListID', choicejsOptions);
document.querySelector('form').addEventListener('reset', function () {
console.log('reset');
// console.log(selectList);
selectList.setChoices(function () {
return selectList.config.choices.map(({ value, label }) => ({
value,
label,
selected: false,
}));
});
});
}); |
Even the documentation shows the bug. It removes all of the options when I click the reset button |
No news? I can't clean my selections... Thanks |
A work-around (snippet from a Stimulus controller): const choices = new Choices(this.element, {
allowHTML: false,
removeItemButton: this.element.multiple,
});
const form = this.element.closest("form");
if (!form) return;
form.addEventListener("reset", () => {
choices.destroy();
choices.init();
}); |
Implemented as part of #1166 |
I have a form with some filters that make an ajax request to display a table. When I want to reset the filters ( $("#filter-form").trigger("reset");) all the select elements created with choices.js are empty and I have nothing left to select. I have to refresh the page to repopulate the select forms.
any ideea ?
The text was updated successfully, but these errors were encountered: