Comments (10)
Interesting. So, if I understand correctly, the MutationObserver
is not the problem. It is the this.tomSelect.destroy()
that causes the problem, right? Could it make sense just to remove that? Iirc, we added it just to do responsible cleanup, but perhaps that was overeager.
See #1219
from ux.
Thanks for the reply - I'll try to create a reproducer, with minimal cases with TomSelect and UX, and get back to you.
from ux.
Repo, info and reproduction steps in README: https://github.com/owsy/sortablejs-symfony-ux-autocomplete
I've not tried to debug this further yet but will take a look as soon as I have time.
from ux.
@rodnaph THANK you. But is the repos private? I got a 404
from ux.
@weaverryan Gah, schoolboy... apologies I thought I made it public, it's visible now. 👍
from ux.
Well, there is something weird, and i'm not sure if our script should handle that or Sortable...
but big picture, the "disconnect
" is triggered by Stimulus on drag:start, and the connect
is immediately trigger in an other dom position....
But while "in the air" by Sortable, TomSelect seems to have not synchronized yet the value to the initial field...
... so when the drop ends, we already have resetted the value / options.
![Capture d’écran 2023-10-25 à 02 32 15](https://private-user-images.githubusercontent.com/1359581/277839955-f68c4050-2a17-4697-bd8b-633017a676d3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDYzNzc3NjIsIm5iZiI6MTcwNjM3NzQ2MiwicGF0aCI6Ii8xMzU5NTgxLzI3NzgzOTk1NS1mNjhjNDA1MC0yYTE3LTQ2OTctYmQ4Yi02MzMwMTdhNjc2ZDMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDEyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAxMjdUMTc0NDIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTYzMzU5Mjc5NTMyMGFmMDUxZTAyMzI1YWYxZmFhYzJiMmE4OTBkODU3YzAwYTdhNTYzMDc1OGMzNzliYzI2MSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.RpxMUQmsqaFkm4N-g3cRqTtzCm9MZmHikmSb6deeGMc)
![Capture d’écran 2023-10-25 à 02 25 59](https://private-user-images.githubusercontent.com/1359581/277839959-16d60e70-ce90-4bb1-9148-7a3abe405e23.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDYzNzc3NjIsIm5iZiI6MTcwNjM3NzQ2MiwicGF0aCI6Ii8xMzU5NTgxLzI3NzgzOTk1OS0xNmQ2MGU3MC1jZTkwLTRiYjEtOTE0OC03YTNhYmU0MDVlMjMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDEyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAxMjdUMTc0NDIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NThiZDJhMzQ0YTVmYjM1ZWUxZTBjMDI3MThlZWQwNWNkMzE1Y2I2NDNjMjk2MGQ5OGExYmE3MWVkMGZlMTk4YSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.3XsrWpx2L_hHbJH4RgkMQ19cdt-PqbSino_PNDIM4KU)
(and i lost time with required / not, multiple / not and data-attributes haha)
from ux.
And it does work with your patch @weaverryan
So it's indeed something with the destroy beeing called before the value is sync back into the HTML
Update:
i confirm as soon the element is injected in another place in the DOM, the select has no value.
![Capture d’écran 2023-10-25 à 02 49 06](https://private-user-images.githubusercontent.com/1359581/277841604-9d066429-783b-4cf9-ba59-edb06fcacc4a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDYzNzc3NjIsIm5iZiI6MTcwNjM3NzQ2MiwicGF0aCI6Ii8xMzU5NTgxLzI3Nzg0MTYwNC05ZDA2NjQyOS03ODNiLTRjZjktYmE1OS1lZGIwNmZjYWNjNGEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDEyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAxMjdUMTc0NDIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjhiM2NlZjZmN2U0YTQyZDUyOWE0OTcwNTZjYTVmZTc2MDg5MmZkZmRhYTRkNWFmY2JiNTRkODAwZTIyMDc5NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.3T5hNZk8EXv5ahhjIbwNtLeFCMzOITF8b8ZPOSE4KKw)
from ux.
@smnandre Thanks for taking the time to look at this.
Well, there is something weird, and i'm not sure if our script should handle that or Sortable...
I was also not sure where the issue lies, if autocomplete even needs to change, but as a plain TomSelect with SortableJS does not have this issue I figured perhaps that's a sign it should be supported here.
But while "in the air" by Sortable, TomSelect seems to have not synchronized yet the value to the initial field...
My initial attempt to work around this was to force TomSelect to flush the value onchange, but it does not have any public methods for this (as you can see from the workaround code in my description). And again, the plain TomSelect does work...
Anyway, thanks to anyone spending time on this, I realise it's something of an edge-case in as much as it's support for one particular other library, but SortableJS has been suggested in other threads for the basis for a UX sortable component, so might be useful to understand what's going on.
from ux.
SortableJS has been suggested in other threads for the basis for a #1071, so might be useful to understand what's going on.
💯
And even more, if than happens there, that probably happen with other librairies, so it's something to look at :)
If the @weaverryan solution (not destroying the instance) has no other consequences than "philosophical" ones, i'd say we use it for now (with a warning/information ?)
from ux.
I spent some time to look for a solution, and...
- the bug comes from TomSelect (see orchidjs/tom-select#562 )
- we could "manually" store the correct value in the input (see example[^1]) .. but it's not cleaner than "not destroying" ...
So i'm even more for your solution @weaverryan ...
(if we really wanted to avoid memory loss, we could add a "timer" and destroy the instance if the element has not been re-connected after some time....)
[^1] : something like
// PSEUDO CODE (does not handle multiple options...)
disconnect() {
this.stopMutationObserver();
const value = this.element.value;
this.tomSelect.destroy();
this.element.value = value;
}
```
from ux.
Related Issues (20)
- [LiveComponent][Documentation] Unclear instructions for Javascript HOT 9
- [Autocomplete] Fetch results with elasticsearch HOT 3
- [UX Live] Wrong display value for loading element show HOT 5
- [Autocomplete] Module build failed @symfony/ux-autocomplete/package.json" could not be found HOT 3
- [LiveComponent] data-loading behaviour not working correctly in child components HOT 7
- [LiveComponent] addCollectionItem don't work when using DTO as source HOT 4
- [UX] 503 error with opcache JIT enabled HOT 5
- [TwigComponent] props reflexion HOT 7
- [TogglePassword] htmlspecialchars for button-classes HOT 4
- [TwigComponent][LiveComponent] Compatibility with Twig 2.9 / use_yield HOT 4
- Documentation could be improved by being clear about incompatibility with AssetMapper HOT 6
- [LiveComponent] Loading state on specific form fields, documentation incomplete HOT 1
- [LiveComponent] Form re-render only possible with live-id on component instantiation
- import { getComponent } @symfony/ux-live-component with AssetMapper not working HOT 4
- [Live Component] Datepicker bug at onchange HOT 5
- [Twig] avoid need for `{{ }}` around spread operator when using html-syntax HOT 4
- [Chart.js] Stimulus connect is called multiple time causing errors
- [Live Component] The User cannot be retrieved from a component extending AbstractController HOT 6
- [LiveComponent] Reinitializing Choices.js plugins HOT 5
- The file "@symfony/ux-chartjs/package.json" could not be found HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ux.