-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring the Work policy wizard JavaScript functionality without (#…
…1907) jQuery and outside of the <script> element. Co-authored-by: Hector Correa <[email protected]>
- Loading branch information
1 parent
889b3e9
commit e875cc4
Showing
3 changed files
with
50 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class WorksWizardPolicy { | ||
static bind(elementSelector) { | ||
let built; | ||
const root = document.querySelector(elementSelector); | ||
|
||
if (root) { | ||
built = new WorksWizardPolicy(root, '#submit-button'); | ||
} | ||
|
||
return built; | ||
} | ||
|
||
handleChange(event) { | ||
const { classList } = this.submitButton; | ||
|
||
if (event.target.checked) { | ||
classList.remove('btn-secondary'); | ||
classList.remove('disabled'); | ||
classList.add('btn-primary'); | ||
|
||
this.submitButton.disabled = false; | ||
} else { | ||
classList.remove('btn-primary'); | ||
classList.add('disabled'); | ||
classList.add('btn-secondary'); | ||
|
||
this.submitButton.disabled = true; | ||
} | ||
} | ||
|
||
constructor(root, buttonSelector) { | ||
this.root = root; | ||
this.submitButton = null; | ||
|
||
if (this.root) { | ||
const submitButton = document.querySelector(buttonSelector); | ||
|
||
if (submitButton) { | ||
this.submitButton = submitButton; | ||
const handleChange = this.handleChange.bind(this); | ||
this.root.addEventListener('change', handleChange); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default WorksWizardPolicy; |
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