-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Backpex.Fields.HasMany
#554
Conversation
57aed82
to
6cf2558
Compare
@impl Backpex.Field | ||
def before_changeset(changeset, attrs, _metadata, repo, field, assigns) do | ||
{field_name, field_options} = field | ||
validate_live_resource(field_name, field_options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things like this should be done way more generic and for every field / filter / etc. (in the future).
https://github.com/dashbitco/nimble_options
Maybe even on compile time.
defp validate_posts(changeset) do | ||
posts = get_field(changeset, :posts) || [] | ||
|
||
if length(posts) < 1 do | ||
add_error(changeset, :posts, "must have at least one post") | ||
else | ||
changeset | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea: We could provide a generic version of this via Backpex.Ecto.ChangesetHelpers.validate_assoc_length
or something like that (in the future).
Backpex.Field.HasMany
to derive everything from the formbefore_changeset
callback to fieldsresource.ex
(see upgrade guide)