Search code examples
f#elmishbolero

Bolero datetime bind


The docs say that you can bind many different data types...

My html template:

  <div class="field">
    <label class="label">Dob</label>
    <div class="control">
      <input class="input" type="date" placeholder="Date of Birth..." bind="${Dob}">
    </div>
  </div>

And my code is:

  .Dob(model.client.dob, fun n -> dispatch (SetDob n))

But I get a red underline on model.client.dob because it's expecting a string.... what is the correct way of doing this?


Solution

  • Assuming it's probably something like this?

            .Dob(
                model.client.dob.ToString("yyyy-MM-dd"), 
                fun n -> 
                    let dt = DateTimeOffset.Parse(n)
                    dispatch (SetDob dt)
            )
    

    I would have thought that was built in... from how the docs talk about