mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-23 09:41:05 +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
|
@ -1037,7 +1037,7 @@ const noop = () => {};
|
|||
* @param {string} value The new value of the element
|
||||
*/
|
||||
const changeElementValue = function (el) {
|
||||
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
||||
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
||||
const elementToChange = el;
|
||||
elementToChange.value = value;
|
||||
const event = new CustomEvent("change", {
|
||||
|
@ -1167,13 +1167,21 @@ const enhanceComboBox = _comboBoxEl => {
|
|||
placeholder
|
||||
});
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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) || (!optionEl.value && !defaultValue)) {
|
||||
selectedOption = optionEl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1500,16 +1508,27 @@ const resetSelection = el => {
|
|||
} = getComboBoxContext(el);
|
||||
const selectValue = selectEl.value;
|
||||
const inputValue = (inputEl.value || "").toLowerCase();
|
||||
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;
|
||||
// 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 ((!selectValue && !optionEl.value) || optionEl.value === selectValue) {
|
||||
if (inputValue !== optionEl.text) {
|
||||
changeElementValue(inputEl, optionEl.text);
|
||||
}
|
||||
comboBoxEl.classList.add(COMBO_BOX_PRISTINE_CLASS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (inputValue) {
|
||||
|
|
|
@ -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