Hello everyone! I read in Phoenix live view docs it is generally a good idea to handle events in a component, not in parent live view, cause the server sends new data only needed for component and this helps UX in general. So I decided to add form validation to my live component:
def handle_event("validate", %{"user" => %{"email" => email}}, socket) do
That is how my form validating is happening in parent LiveView. My first move was to put phx-target on form. After that I have got an error about my second argument in handle_event function:
(KeyError) key :user not found in: %{_changed_: %{}, … , user_changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [username: {“can’t be blank”, [validation: :required]}], data: #MyApp.Accounts.User<>, valid?: false>}
As you can see in the error log there is no :user key. Maybe there is something about my changeset? I declare it in part LiveView mount then pass it to Component. If it is - is it so bad to initialize changeset both in Live Component and parent Live View?