Using Knockout.js how do bind a Date property to a HTML5 date picker?

后端 未结 8 697
南旧
南旧 2021-01-04 00:37

(this only works in Chrome at the moment as most browsers don\'t yet implement date picker for input type=\"date\")

In the following example MyDate starts o

8条回答
  •  梦谈多话
    2021-01-04 01:12

    From HTML 5 - Input type date formatting on iOS

    There are two formats at play:

    • displayed format
    • internal format exposed to JavaScript and sent to the server

    You cannot change the display format. It's up to the browser to decide how the date is presented to the user (in practice it's determined by system's locale).

    You cannot change the internal format either. It's always ISO8601, regardless of browser/locale.

    You'll have to pre-populate it with that specific format, and you can add a computed observable to parse it into a Date object, so you can read it at other places in your application.

    If you also want to write to it from JS, you could set up a writeable computed observable and parse the input to see if it's a string from the input field, or a Date object from your JS.

提交回复
热议问题