I hava a Collection, in which a field User (a multiselect) depends on a previous Select, the Department. Therefore each User select contain a different "value_options".
How can I set different "value_options" when retrieving the form for each row of the Collection?
You have different options:
I personally discourage the second option. Is there just to say that it is a possible solution, but NO.
The first option, the API, is interesting, but requires actually more work, especially if it is the only endpoint in your application.
The third option is the one I always use, since it requires the less code and it quite simple to implement.
In your form, you have your two elements:
As you can see, all the users are put in the
value_options. Keep in mind that this is just an example, you should use custom elements to populate this kind of selects ;)Then, in your view, you render the elements:
And you finally add the JS code to handle the filter. Here I use
jQuery, but it's not necessary to use it:Final tip: don't forget to create and add to the form a
Validatorto check the coupledepartment_id - user_idis correct, just to avoid (on my example) to accept Lara Doe (logistic) with IT department ;)