-
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
Restore select to initial value #1023
Comments
Is there a solution for this issue? |
We experienced the same problem. We call form.reset() between each page load. My guess is that _initialState should contains the data of _preset* at line 297 (before the bind calls) |
I am experiencing the same issue. Did anybody find a solution? |
No feedback on this? There is at least another one issue about this problem, with no answer #1053 |
@yanmorinokamca I followed you analysis looking at the code and I guess you got it right... did you find any solution? |
As a temporary workaround in my application I managed to intercept reset event on the form and then repopulate all the options by hand:
This should be unnecessary but at least my app does work. I hope this will be fixed at some point. |
Hi, we didn't have time to debug the library, so we replaced the form.reset() with a custom reset of each field. |
I see. Unfortunately I cannot explicitly reset each field because it is a component that has to handle different forms, with many different fields. Thanks for your reply. |
@masiorama I tried your code and saw that the event is not triggered: const choicesTagsObj = new Choices('#choices-tags', {
maxItemCount: 4,
removeItemButton: true,
allowHTML: false,
position: 'bottom',
itemSelectText: 'Push',
maxItemText: (maxItemCount) => {
return `Only ${maxItemCount} can be selected`;
},
});
document.getElementById('choices-tags').addEventListener('reset', (ev) => {
console.log('reset');
}) what's the problem? After some minutesSome points:
Working code: let choicesTags = document.getElementById("choices-tags");
//copy full select node with values
let choicesTagsBefore = choicesTags.cloneNode(true);
//convert to array
choicesTagsBefore = Array.from(choicesTagsBefore.options);
const choicesTagsObj = new Choices(choicesTags, {
maxItemCount: 4,
removeItemButton: true,
allowHTML: false,
position: 'bottom',
itemSelectText: 'Push',
maxItemText: (maxItemCount) => {
return `Only ${maxItemCount} can be selected`;
},
});
//fill again after form reset (Choices.js bug workaround)
document.getElementById('therapy-form').addEventListener('reset', (ev) => {
// console.log('reset');
choicesTagsObj.setChoices(async () => {
return choicesTagsBefore.map(({ value, label }) => ({
value,
label,
selected: false,
}));
});
}) |
Bisected to: 68313da (which is the conversion to TypeScript 🥲) Tracked down to - // Set initial state (We need to clone the state because some reducers
- // modify the inner objects properties in the state) 🤢
- this._initialState = cloneObject(this._store.state); after Choices/src/scripts/choices.ts Line 343 in 5dbea28
|
* Typescript config setup * Add type annotations to components * Further type additions * And more... * Add types to actions * Add types to templates * Further type checks * Further type additons * Install fuse latest * Housekeeping * Remove old type definitions * Fix remaning type issues * Fix some failing tests * Remove types workflow * Fix failing unit tests * Resolve back space event regression * Convert cypress files to .ts * Fix eslint issues * Remove cachebusting urls * Resolve delete button bug * Resolve regression bugs * Fix lint script * Fix lint workflow * Pass args instead of object to keyboard handlers * Flatten misc reducer * Resolve keyboad action test failures * Use Pick instead of Partial * Use interfaces in action tests * Update firefox image * Incorporate #791 * Incorporate #788
I've encountered this issue now and hoping to see this fixed soon. |
Implemented as part of #1166 |
hey,
I checked the live preview in the documentation, the button to reset the form (
button type="reset"
) causes select not to keep the default value, select is emptythis feature works fine in version 9.0.1, the bug has appeared since version 9.1.0
how to reproduce the issue:
The text was updated successfully, but these errors were encountered: