I have form which I check for valid input etc. If something is wrong with the form I will call preventDefault() method on submit event and therefore form will not be submitted yet Firefox still shows me pop up box prompting me to save password.
Yeah I can see that but it is confusing that you still can see that box even in cases when passwords are not matching and therefore form is not submitted. In this situation user can save passwords that are not even submitted anywhere
I can confirm, that you can’t stop Firefox from asking if the password should be saved.
All I can recommend in that regard is that you make it very clear to the user that the password wasn’t correct, to help encourage them to not save the bad password.
Firefox won’t ask you to save the password if the form is actually invalid though. I think there are 2 possibilities to require the passwords to match; one would be to check if the values are equal manually and .setCustomValidity() if not:
const form = document.querySelector('form')
const [password1, password2] = form.querySelectorAll('[type="password"]')
form.addEventListener('input', () => {
if (password1.value !== password2.value) {
password2.setCustomValidity('The passwords must match!')
} else {
password2.setCustomValidity('')
}
})
form.addEventListener('submit', e => {
e.preventDefault()
// ...
})