I would like the tag_color drop down options to change dynamically depending on the post_type input. I mean there are many post types in my case like regular, news and attached content.
I would like to tag_color drop down to show [:red, :green] for all post_type inputs except attached_content which will need to have tag_color drop down with all three tag_color options [:red, :blue, :green]. How to set this conditionally? I am not sure where this logic should take place and how.
If I debug and see, what happens is, first the form gets nil values for all fields since the form is being initiated, next a set of invalid attributes(i.e, post_name: nil) are passed to make sure the form returns the expected output. But after the render_change, when I pass the attrs with blue tag color, I get the following error:
** (ArgumentError) value for select "post[tag_color]" must be one of ["red", "green"], got: "blue"
code: |> render_submit()
I believe this error is caused by render_change followed by render_submit. Any suggestion on how this can be resolved?
I believe you need to split your input into two steps. first input post_type: “attached_content” and then pipe to render_change. “blue” does not get added to your list of options until that change is handled by the live view. then you can pipe to input tag_color: “blue” and render_submit.
This may seem like extra steps but these are the same steps your live view is taking as you input the post type on the page