-
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.
💅 big old refactors for the barest hint of separation of concerns
- Loading branch information
Showing
3 changed files
with
139 additions
and
134 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,21 @@ | ||
export function updateSelectOptions($select, newOptions) { | ||
// Get the current selected option | ||
const currentText = $select.find("option:selected").text(); | ||
|
||
// Create a new set of options from the new options array | ||
const $newOptions = newOptions.map((option, index) => { | ||
return $("<option>", { value: index, text: option }); | ||
}); | ||
|
||
// Empty the current select options | ||
$select.empty(); | ||
|
||
// Append the new set of options | ||
$select.append($newOptions); | ||
|
||
// Select the previously selected option, if it exists in the new options | ||
const optionWithCurrentText = $select.find("option").filter(function () { | ||
return $(this).html() == currentText; | ||
}); | ||
$select.val(optionWithCurrentText.val()); | ||
} |
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