As simple as the title states, why is the e.PreventDefault
not executing while all the alerts are?
I only want the page to be forwarded when the alert "All details match" is fired. My code: https://jsfiddle.net/3fmru8oa/
This is the section I am asking about
<script>
function loginValidator() {
const submitButton = document.getElementById("form");
const username = document.getElementById('uid')
const password = document.getElementById('pwd')
const db = new Localbase("vChatDataBase")
submitButton.addEventListener('submit', function (e) {
console.log(`Inputed field uid: ${username.value}`)
console.log(`Inputed field pwd: ${password.value}`)
db.config.debug = false
db.collection('users').doc({ username: username.value }).get().then(document => {
if(document === undefined) {
alert("No user exist's with this username!")
return e.preventDefault()
} else {
if(document['password'] !== password.value ) {
alert("Incorrect password!")
return e.preventDefault()
} else {
alert("All details matched")
return Cookies.set("cookieUsername", document['username'])
}
}
})
})
}
</script>
I attempted to do this with jQuery yet the same issue remained. I have also tried to return false
Does this have something to do with scoping? And how is this fixed?