on the root form the params are reset to the values before the
update_form
update_form
call. Since a code snippet says more than 1000 words:
# Create form and add author sub-form with default value for email form = AshPhoenix.Form.for_create(Post, :create, forms: [auto?: true]) |> AshPhoenix.Form.add_form(:author, params: %{ "email" => "[email protected]" } ) # Use update form to update the email of the author form = AshPhoenix.Form.update_form(form, :author, fn author_form -> AshPhoenix.Form.update_params(author_form, fn params -> Map.put(params, "email", "[email protected]") end) end) assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "[email protected]" # Now update some other attributes on the root form form = AshPhoenix.Form.update_params(form, fn params -> Map.put(params, "text", "text value") end, only_touched?: true, target: ["text"]) # This fails assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "[email protected]"
# Create form and add author sub-form with default value for email form = AshPhoenix.Form.for_create(Post, :create, forms: [auto?: true]) |> AshPhoenix.Form.add_form(:author, params: %{ "email" => "[email protected]" } ) # Use update form to update the email of the author form = AshPhoenix.Form.update_form(form, :author, fn author_form -> AshPhoenix.Form.update_params(author_form, fn params -> Map.put(params, "email", "[email protected]") end) end) assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "[email protected]" # Now update some other attributes on the root form form = AshPhoenix.Form.update_params(form, fn params -> Map.put(params, "text", "text value") end, only_touched?: true, target: ["text"]) # This fails assert AshPhoenix.Form.get_form(form, [:author]) |> AshPhoenix.Form.value(:email) == "[email protected]"
I'm wondering whether this is a bug or if there's something I'm missing in the usage of
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.