Creating a vnode with a CSS selector for input[type=date] and assigning special IDL attribute valueAsNumber fails with an error message.
Could be related to attribute precedence:
https://mithril.js.org/hyperscript.html#attributes-passed-as-the-second-argument
Mithril version: 2.0.4
Browser and OS: Firefox 80.0 / Ubuntu 20.04
Fiddle: https://jsfiddle.net/mhz74q8v/
const timestamp = (str) => new Date(str).getTime();
let limits = ['2020-01-01', '2020-12-31'].map(timestamp)
let range = limits
const WorkingExample = {
view() {
return m('input', {
type: 'date',
valueAsNumber: range[0]
});
}
}
/* Throws Error: InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable" */
const ThisBreaks = {
view() {
return m('input[type=date]', {
valueAsNumber: range[0]
});
}
}
m.mount(document.body, ThisBreaks)
Defining a data[type=input] and setting the special attribute valueAsNumber should work.
An error is thrown: InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
Checked the generated hyperscript vnode, and it's an issue with property application order - the type appears after valueAsNumber.
The fix would be special-casing input.type to be applied before other properties, similar to how select.selectedValue is special-cased to apply after children are rendered.
Fixed by #2578.