Hacker News new | past | comments | ask | show | jobs | submit login

If a default value is set you’re going to have the problem of people skipping the field and submitting the default value instead. What is needed is a way of influencing the picker’s default view into year view with a default year visible, but without actually setting a default value. Only Apple can provide that level of control.



Hmmm, yeah I suppose that's true when using the `value` attribute,

EDIT: ignore the below. It was pointed out I misinterpreted defaultValue.

but there's actually also a `defaultValue` attribute which I believe behaves how you would like it to:

https://caniuse.com/mdn-api_htmlinputelement_defaultvalue

Ofc you can also use JS to make sure an input has been blurred or touched to pass validation on submit


That's not what `defaultValue` does. `defaultValue` is a JS (not HTML) attribute which simply allows you to retrieve the original value set in the HTML. So if you have this HTML:

    <input id="foo" value="bar">
Then `document.getElementById('foo').defaultValue` will always return `'bar'`, even if the user has edited the value in the field.


You're right, thanks for the correction.

Then yeah I suppose it'd have to be a javascript trick that sets the default value when the calendar is opened or, as GP suggested, something done at the standards or implementation level


There is always a default value in a picker; if you don't specify one, the UI defaults to today's date.


You’re talking about slightly different things. You’re right that when the UI opens it’s always going to be on a default date, if you don’t set one it’ll be today.

But if you don’t set one then the value of the HTML element will be null before it’s selected. So if you add a required attribute then you can make sure that your users use the date picker (or leave in frustration after failing to do so) before submitting the form.

If you set a default value using the value attribute, then that becomes both the HTML default value and the UI default. IMO the spec is missing a way to just set the UI default, so that the field is default empty but interacting puts it at a sensible starting point.

There’s an MDN example here where the date starts empty and is required, if you try submitting the form you’ll see there’s no default for the HTML element: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/in...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: