Manukam
Hi,
I have a form and when I enter a value to an input field and then erase it, and then make a change to the form like changing a select input from True to False, the erased value reappears. Did a little bit of digging and it looks like when I erase the value, the value is set to an empty string (“”) and this is not considered as a change in the changeset as shown below,
"channels" => %{
"0" => %{
"channel_name" => "test",
"description" => "",
"id" => "a58fa456-53f7-4fee-832b-8f4653af22f6"
}
}
#Ecto.Changeset<
action: :update,
changes: %{},
errors: [description: {"can't be blank", [validation: :required]}],
data: #Webappl<>,
valid?: false
>
]
Any idea how to tell Ecto to consider this as a change?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
joey_the_snake
Change the
empty_valuesoption. It defaults to[""]. More info: Ecto.Changeset — Ecto v3.14.0Manukam
I actually have it as shown below, still the output is the same,
joey_the_snake
Oh sorry I was mistaken.
validate_requiredchecks for empty string and doesn’t considerempty_values.I think your only 2 options are these:
""as anempty_valuebut put a default value on the field. That way when you cast it,""will be changed to the default value andvalidate_requiredwon’t add an error.Manukam
I can’t make it optional, because this is actually an embedded schema (embeds_many - atleast one is required). It shouldn’t be optional, but the issue is, if a user erases the value and then changes something else in the form and when the erased value reappears, its not good UX
I want this field to be set to nil and the error msg shown until the user enters some value again, and it should stay blank even when the user is changing other parts of the form.
when I put the default value as nil and empty_values as “”, still it does not get set to nil
Manukam
Thanks for the inputs. I was able to achieve what I wanted with this method,
[https://stackoverflow.com/questions/45754213/how-to-make-ecto-changeset-validate-required-accept-blank-values]
joey_the_snake
Out of curiosity, how come you can’t make the
descriptionfield on your embedded schema optional? That is the one that is causing the error. You could still do what you are saying and havedescriptionbe optional.I’m asking because I’m wondering if this should be made easier by Ecto. But struggling a bit to understand why that field couldn’t be optional for you.
Manukam
So let me explain the context a little bit. I have a select (True or False) if the user selects True, then a nested form is shown to the user where they have to enter some details, “Description” is in this nested form. So if the user selects True, the fields in this nested form can’t be optional, they are required. But if the user selects, False, then these fields should not be required. (Also, there is a + button, where the user can add more nested forms like this)
I wrote a function to set these fields required or not based on the user’s input.