inputs icon indicating copy to clipboard operation
inputs copied to clipboard

datetime input does not support step attribute

Open mootari opened this issue 2 years ago • 1 comments

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.

mootari avatar Jul 02 '23 09:07 mootari

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;
}

mootari avatar Jul 02 '23 09:07 mootari