Now that Temporal is on its way to stage 4, it is worth considering how <input type="date">
, <input type="time">
, <input type="week">
, <input type="month">
could integrate with this API.
Getting the value of a date input with valueAsDate
returns a Date object. The value of a date input can be set by providing a Date object to valueAsDate
. Converting between a Date object and Temporal is possible but far from ideal. valueAsNumber
returns the number of milliseconds since the Unix epoch, which is also problematic. The optimal approach at the moment is working with the string value of .value
and converting using Temporal.PlainDate.from()
/ Temporal.PlainDateTime.from()
/ Temporal.PlainTime.from()
.
Previous discussion: tc39/proposal-temporal#107 Below is the strawman from that thread updated with the current syntax (the Civil prefix has been changed to Plain).
Add a valueAsTemporal
getter/setter to HTMLInputElement<input type=date>
accepts/returns PlainDate<input type=time>
accepts/returns PlainTime<input type=datetime-local>
accepts/returns PlainDateTime<input type=month>
accepts/returns PlainYearMonth
<input type=week>
does not have a mapping.
Alternatively, separate valueAsPlainDate
, valueAsPlainTime
, valueAsPlainDateTime
, valueAsPlainYearMonth
.
lukewarlow, danburzo, nektro, mtt-artis, WickyNilliams and 6 more
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4