patrickdm

patrickdm

Phoenix.HTML.Form.date_select/3 with null default value

Hello,
I have a resource’s date-field which is optional (so in most records it has a null value) and in the form I render it with date_select/3 (datetime_select/3 for options and supported values)

When I edit a record with a null date-field, date_select displays 2015/01/01 as default value for it.

This date value is then stored on update, along with the actual record’s field I was actually editing.

I tried using the option default: nil in order to avoid the date-field to be updated too, with no success.

I’m bypassing this issue using a text_input/3 field in place of date_select/3, but still wondering if I’m just missing the simple/obvious solution, which I presume is hidden in plain sight to my eyes.

Thank you for any suggestion and help.

Marked As Solved

kokolegorille

kokolegorille

I use date_select with null default value like this.

    <%= 
      date_select f, 
        :expiry_date, 
        year: [prompt: ""], 
        month: [prompt: ""], 
        day: [prompt: ""],
        class: "form-control" 
    %>

Last Post!

patrickdm

patrickdm

Thank you very much, this is exactly what I was aiming for, but couldn’t find the right spell.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement