Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Why**: To resolve multiple bugs
- Loading branch information
Showing
17 changed files
with
20 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,8 @@ | ||
import h5f from 'h5f'; | ||
|
||
import validateField from './validate-field'; | ||
|
||
|
||
const validate = { | ||
init() { | ||
this.form = document.querySelector('form'); | ||
if (!this.form) return; | ||
this.form.noValidate = true; | ||
this.btn = this.form.querySelector('[type=submit]'); | ||
|
||
h5f.setup(this.form, { | ||
validClass: 'valid', | ||
invalidClass: 'invalid', | ||
requiredClass: 'required', | ||
placeholderClass: 'placeholder', | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const form = document.querySelector('form'); | ||
if (form && window.onbeforeunload) { | ||
form.addEventListener('submit', () => { | ||
if (form.checkValidity()) window.onbeforeunload = false; | ||
}); | ||
|
||
this.addEvents(); | ||
}, | ||
|
||
addEvents() { | ||
this.form.addEventListener('change', e => validateField(e.target)); | ||
this.form.addEventListener('submit', e => this.validateForm(e)); | ||
}, | ||
|
||
validateForm(e) { | ||
if (!this.form.checkValidity()) { | ||
if (this.pageUnloader) { | ||
window.onbeforeunload = this.pageUnloader; | ||
} | ||
e.preventDefault(); | ||
} else { | ||
this.pageUnloader = window.onbeforeunload; | ||
window.onbeforeunload = false; | ||
} | ||
|
||
const fields = this.form.querySelectorAll('.field'); | ||
for (let i = 0; i < fields.length; i++) { | ||
validateField(fields[i]); | ||
} | ||
|
||
// add focus to first invalid input | ||
const invalidField = this.form.querySelector('.invalid, .interacted.required'); | ||
if (invalidField) invalidField.focus(); | ||
}, | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', () => validate.init()); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters