Here’s my field:
typed_schema "onboardings" do
field(:mood_influencers, {:array, :string}, default: [])
timestamps(type: :utc_datetime_usec)
end
And my changeset:
|> validate_required([
:user_id,
:mood_influencers,
])
|> validate_length(:mood_influencers, min: 1, max: 12)
|> validate_subset(:mood_influencers, [
"A",
"B",
"C"
])
But when no my {:array, :string} field is empty (no selected checkboxes), there is no changeset error.
#Ecto.Changeset<
action: nil,
changes: %{
mood_rating: 5,
motivation_rating: "Somewhat Motivated",
positivity_boost_will_work: "Yes"
},
errors: [user_id: {"can't be blank", [validation: :required]}],
data: #App.Programs.Onboarding<>,
valid?: false
>
I’m looking for an error that is like: “You need to select at least one item from the list of options.”
I thought validates_required
would take care of this.