Skip to content
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

Detect empty_values inside lists when casting. #3840

Merged
merged 2 commits into from
Feb 28, 2022

Conversation

marcandre
Copy link
Contributor

See https://elixirforum.com/t/phoenix-casting-multiple-checkboxes-to-array-ecto-enum/46252/6

This way, an HTML form with checkboxes having names ending with [] can have
a hidden input with empty value to ensure the presence of that parameter
if none of the checkboxes are checked.

This way, an HTML form with checkboxes having names ending with `[]` can have
a hidden input with empty value to ensure the presence of that parameter
if none of the checkboxes are checked.
lib/ecto/type.ex Outdated Show resolved Hide resolved
@josevalim josevalim merged commit 78ff739 into elixir-ecto:master Feb 28, 2022
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@marcandre marcandre deleted the empty_values branch March 1, 2022 13:10
@leandrocp
Copy link
Contributor

leandrocp commented Apr 28, 2022

Hi @marcandre and @josevalim I just found out this PR has caused a breaking change on our app because oddly enough we were relying on the old behavior, ie: we expect the changeset to keep "" 😆

It's kinda an easy fix on our side and the change is welcome, I'm just wondering if it's worth adding a note on CHANGELOG.md that it's potentially a breaking change, something like:

[Ecto.Changeset] Detect empty_values inside lists when casting. Note it may be a breaking chance if you expect the value "" to be returned.

@marcandre
Copy link
Contributor Author

marcandre commented Apr 29, 2022

Sounds like a good idea. I'm trying to double check if it was included in version 3.7.2, but that commit (960725b) "does not belong to any branch on this repository"...

Ah, done as d382713

@fuelen
Copy link
Contributor

fuelen commented May 4, 2022

Another breaking change that I've noticed is that this code now doesn't put the error "can't be blank" into changeset:

{%{}, %{uris: {:array, :string}}}
|> Ecto.Changeset.cast(%{uris: []}, [:uris], empty_values: ["", []])
|> Ecto.Changeset.validate_required(:uris)

but it was there in Ecto. 3.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants