LiveView - nested form phx_change validation question

There is a LiveView rendered form:

<%= form_for @changeset, @action, [method: @method, phx_change: :validate, phx_submit: :submit], fn f -> %>

Which means that the form is validated on changes. Current error_helpers.ex has the

phx_feedback_for: input_name(form, field)

line. This means that field, which weren’t yet “touched” do not show the validation “feedback”, except… that the “nested” part does. Either

|> cast_assoc(:items)
|> validate_length(:items, min: 1)

or

|> cast_assoc(:items, required: true)

displays the feedback on changes to any other field, before the user even has a chance to add the first item. Any quick solutions to this?

2 Likes