mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-23 17:51:03 +02:00
additional edits to uswds and to combobox.js to accomodate for empty values in options
This commit is contained in:
parent
ea509f63ef
commit
1ca52b49bb
2 changed files with 37 additions and 18 deletions
|
@ -1167,15 +1167,23 @@ const enhanceComboBox = _comboBoxEl => {
|
|||
placeholder
|
||||
});
|
||||
}
|
||||
if (defaultValue) {
|
||||
// DOTGOV - allowing for defaultValue to be empty
|
||||
//if (defaultValue) {
|
||||
// for (let i = 0, len = selectEl.options.length; i < len; i += 1) {
|
||||
// const optionEl = selectEl.options[i];
|
||||
// if (optionEl.value === defaultValue) {
|
||||
// selectedOption = optionEl;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
for (let i = 0, len = selectEl.options.length; i < len; i += 1) {
|
||||
const optionEl = selectEl.options[i];
|
||||
if (optionEl.value === defaultValue) {
|
||||
if ((optionEl.value === defaultValue) || (!optionEl.value && !defaultValue)) {
|
||||
selectedOption = optionEl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw error if combobox is missing a label or label is missing
|
||||
|
@ -1500,10 +1508,22 @@ const resetSelection = el => {
|
|||
} = getComboBoxContext(el);
|
||||
const selectValue = selectEl.value;
|
||||
const inputValue = (inputEl.value || "").toLowerCase();
|
||||
if (selectValue) {
|
||||
// DOTGOV - allow for option value to be empty string
|
||||
//if (selectValue) {
|
||||
// for (let i = 0, len = selectEl.options.length; i < len; i += 1) {
|
||||
// const optionEl = selectEl.options[i];
|
||||
// if (optionEl.value === selectValue) {
|
||||
// if (inputValue !== optionEl.text) {
|
||||
// changeElementValue(inputEl, optionEl.text);
|
||||
// }
|
||||
// comboBoxEl.classList.add(COMBO_BOX_PRISTINE_CLASS);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
for (let i = 0, len = selectEl.options.length; i < len; i += 1) {
|
||||
const optionEl = selectEl.options[i];
|
||||
if (optionEl.value === selectValue) {
|
||||
if ((!selectValue && !optionEl.value) || optionEl.value === selectValue) {
|
||||
if (inputValue !== optionEl.text) {
|
||||
changeElementValue(inputEl, optionEl.text);
|
||||
}
|
||||
|
@ -1511,7 +1531,6 @@ const resetSelection = el => {
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inputValue) {
|
||||
changeElementValue(inputEl);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export function loadInitialValuesForComboBoxes() {
|
|||
|
||||
// Change the default input behaviour - have it reset to the data default instead
|
||||
clearInputButton.addEventListener("click", (e) => {
|
||||
if (overrideDefaultClearButton && initialValue) {
|
||||
if (overrideDefaultClearButton) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
input.click();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue