You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see a strange behaviour when trying to set the query_parameters of a Select2-form field. I have set query_parameters to ['var' => ''] in my form and it shows in the source-code of my page alright.
I now need to fill "var" with a value from another form-element dynamically, but the change is ignored and the value not sent to my remote_route. This strangely only happens when the change of the query_parameters are done in the onchange-event of the other field.
"var" is just empty in my remote_route in this case.
I have checked the contents of "var" using console.log($('#my_element').data('query-parameters')); before and after setting it and the change is done in both cases (!), only when setting it in the onchange-event, it is not transmitted to the remote_route.
The text was updated successfully, but these errors were encountered:
I did some more research on this and found something: In select2entity.js the following line (146) seems to initialize the fields: $('.select2entity[data-autostart="true"]').select2entity();
but that happens only once on document.ready, so my guess (I'm not good at JavaScript) is that once the page is loaded, the select2-fields are initialized, the query-parameters are taken from data-query-parameters, but that's it, the select2-fields won't get notified of any change in data-query-parameters, so the new value is never transmitted to the controller.
Just to test this, I changed my code and did this:
This wil basically re-initialize the select2-fields after "another_element" changes and have the select2-fields re-read the (now changed) value from "my_element".
I have no idea (once again: JavaScript ...) if this will break or overwrite anything in the select2-fields, but this actually resolves the problem and sends the (changed) values to the controller.
Don't know if this is a valid fix, so I'd appreciate if someone could verify this.
(I guess it would probably better, if the bundle read the current data-query-parameters before sending the request to the controller, making the re-initialization obsolete, but I have no idea how to do this.)
I see a strange behaviour when trying to set the query_parameters of a Select2-form field. I have set query_parameters to
['var' => '']
in my form and it shows in the source-code of my page alright.I now need to fill "var" with a value from another form-element dynamically, but the change is ignored and the value not sent to my remote_route. This strangely only happens when the change of the query_parameters are done in the onchange-event of the other field.
What works:
Now I receive "value" in "var" in my remote_route and can process it.
What does NOT work:
"var" is just empty in my remote_route in this case.
I have checked the contents of "var" using
console.log($('#my_element').data('query-parameters'));
before and after setting it and the change is done in both cases (!), only when setting it in the onchange-event, it is not transmitted to the remote_route.The text was updated successfully, but these errors were encountered: