KiKi
Hi guys,
I’m working on a blog and each post can have a “draft” or “published” status. In my changeset, I’ve set a changeset validation for min number of characters. I want this validation to check number of characters only if you want to publish a post.
For example, if you’re just writing a draft, it can be empty or have any number of characters but if you want to publish it, it needs to have at least 5000 characters.
I have a draft changeset but I also have a publish changeset with all the validations.
The problem is, if you save a post as draft and then you get back and want to publish it but you don’t change the post, it will be published even if it has less then 5000 characters.
The thing is, if the post is not changed, it will not be part of changeset.changes and it will skip validation so my question is; how do I force this validation on a data that’s part of Post struct and not part of changeset_changes?
Trending in Discussions
Other Trending Topics
Latest Phoenix Threads
Latest on Elixir Forum
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
- #channels
- #elixirconf
- #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
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You can use
Ecto.Changeset.force_change.