Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime input does not support step attribute #255

Open
mootari opened this issue Jul 2, 2023 · 1 comment
Open

datetime input does not support step attribute #255

mootari opened this issue Jul 2, 2023 · 1 comment

Comments

@mootari
Copy link
Member

mootari commented Jul 2, 2023

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
Copy link
Member Author

mootari commented Jul 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant