fix(linked_dropdown/dropdown): for dropdown_list, drop blank option because rails add it when the field is required. kind of same behaviour for linked_dropdown_list [but requires to manage it on the front too]
This commit is contained in:
parent
7ad47f3eae
commit
4c0aac8e0c
6 changed files with 30 additions and 10 deletions
|
@ -13,15 +13,19 @@ delegate('change', PRIMARY_SELECTOR, (evt) => {
|
|||
|
||||
selectOptions(secondary, options[primary.value]);
|
||||
});
|
||||
|
||||
function makeOption(option) {
|
||||
let element = document.createElement('option');
|
||||
element.textContent = option;
|
||||
element.value = option;
|
||||
return element;
|
||||
}
|
||||
function selectOptions(selectElement, options) {
|
||||
selectElement.innerHTML = '';
|
||||
|
||||
if (selectElement.required) {
|
||||
selectElement.appendChild(makeOption(''));
|
||||
}
|
||||
for (let option of options) {
|
||||
let element = document.createElement('option');
|
||||
element.textContent = option;
|
||||
element.value = option;
|
||||
selectElement.appendChild(element);
|
||||
selectElement.appendChild(makeOption(option));
|
||||
}
|
||||
|
||||
selectElement.selectedIndex = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue