inputs
inputs copied to clipboard
datetime input does not support step attribute
Inputs of type datetime-local may specify a step attribute to set the input's granularity. The attribute value defaults to "60" but can be set to "1" to allow entering seconds.
Passing step in the Inputs.datetime() options does not change the input's granularity. Instead, the step attribute has to be applied after the input was created.
Workaround:
function datetimeInput({step, value, ...options} = {}) {
const form = Inputs.datetime({value, ...options});
if(step == null) return form;
form.date.step = step;
if(value != null) {
value = new Date(value);
form.date.value = (new Date(+value - value.getTimezoneOffset() * 1000 * 60)).toISOString().slice(0, 19);
form.date.dispatchEvent(new Event("input"));
}
return form;
}