-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added nojquery for addressbook display logic (#790)
Co-authored-by: Bettina Bröthaler <[email protected]>
- Loading branch information
1 parent
d8d585a
commit 51e8d2a
Showing
2 changed files
with
44 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Addressbook checkout component | ||
* This handles a dropdown or radio buttons containing existing addresses or payment methods, | ||
* with one of the options being "create a new ____". When that last option is selected, the | ||
* other fields need to be shown, otherwise they need to be hidden. | ||
*/ | ||
function onExistingValueChange() { | ||
let existingValues = document.querySelectorAll('.hasExistingValues'); | ||
if(!existingValues) return; | ||
|
||
existingValues.forEach(function (container, idx) { | ||
let toggle = document.querySelector('.existingValues select, .existingValues input:checked'); | ||
|
||
// visible if the value is not an ID (numeric) | ||
let toggleState = Number.isNaN(parseInt(toggle.value)); | ||
let toggleFields = container.querySelectorAll(".field:not(.existingValues)"); | ||
|
||
// animate the fields - hide or show | ||
if (toggleFields && toggleFields.length > 0) { | ||
toggleFields.forEach(field => { | ||
field.style.display = toggleState ? '' : 'none'; | ||
}) | ||
} | ||
|
||
// clear them out | ||
toggleFields.forEach(field => { | ||
field.querySelectorAll('input, select, textarea').forEach(f => { | ||
f.value = ''; | ||
f.disabled = toggleState ? '' : 'disabled'; | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
let selectors = document.querySelectorAll('.existingValues select'); | ||
if(selectors) selectors.forEach(selector => selector.addEventListener('change', onExistingValueChange)); | ||
|
||
let inputs = document.querySelectorAll('.existingValues input[type=radio]') | ||
if(inputs) inputs.forEach(input => input.addEventListener('click', onExistingValueChange)); | ||
|
||
onExistingValueChange(); // handle initial state |
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