Using the following form in Safari, if you set a date and then use the “clear” button to unset it, Safari will invalidate the form even though it’s valid.
It also doesn’t assign the input element with a validationMessage
. Removing novalidate
, all it does is select the day part of the input.
Am I missing something or is this a Safari bug? The form validates fine in Chrome.
https://jsfiddle.net/n_cholas/zfo9qm6p/27/
<form novalidate>
<input type="datetime-local">
<button type="button">clear</button>
<button>Submit</button>
</form>
<script>
const form = document.getElementsByTagName('form')[0]
const input = document.getElementsByTagName('input')[0]
const btn = document.getElementsByTagName('button')[0]
btn.addEventListener('click', function(e) {
input.value = ''
})
form.addEventListener('submit', function(e) {
e.preventDefault();
console.log('checkValidity', form.checkValidity())
console.log('validationMessage', input.validationMessage)
})
</script>