added select 2 on all fields (with limit of 12)
This commit is contained in:
parent
73dd8f4ce8
commit
4bb0445cff
File diff suppressed because one or more lines are too long
@ -1818,26 +1818,50 @@ function fixedDefaultValue(array $f): string
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
const items = dropdownData[fieldId];
|
||||||
dropdownData[fieldId].forEach(value => {
|
const valToSelect = currentValue || selectedValue;
|
||||||
const option = document.createElement('option');
|
|
||||||
option.value = value.IdCustomFieldsValue;
|
|
||||||
option.textContent = value.Valore;
|
|
||||||
if (currentValue && currentValue === String(value.IdCustomFieldsValue)) {
|
|
||||||
option.selected = true;
|
|
||||||
} else if (!currentValue && selectedValue === String(value.IdCustomFieldsValue)) {
|
|
||||||
option.selected = true;
|
|
||||||
}
|
|
||||||
dropdown.appendChild(option);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ripristina il valore corrente
|
if (items.length > 12) {
|
||||||
if (currentValue || selectedValue) {
|
// Select2 con ricerca
|
||||||
dropdown.value = currentValue || selectedValue;
|
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
||||||
const event = new Event('change', {
|
items.forEach(value => {
|
||||||
bubbles: true
|
const option = document.createElement('option');
|
||||||
|
option.value = value.IdCustomFieldsValue;
|
||||||
|
option.textContent = value.Valore;
|
||||||
|
if (valToSelect && valToSelect === String(value.IdCustomFieldsValue)) {
|
||||||
|
option.selected = true;
|
||||||
|
}
|
||||||
|
dropdown.appendChild(option);
|
||||||
});
|
});
|
||||||
dropdown.dispatchEvent(event);
|
$(dropdown).select2({
|
||||||
|
placeholder: "Seleziona...",
|
||||||
|
allowClear: true,
|
||||||
|
width: '100%'
|
||||||
|
});
|
||||||
|
if (valToSelect) {
|
||||||
|
$(dropdown).val(valToSelect).trigger('change');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Select nativa
|
||||||
|
try {
|
||||||
|
$(dropdown).select2('destroy');
|
||||||
|
} catch (e) {}
|
||||||
|
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
||||||
|
items.forEach(value => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = value.IdCustomFieldsValue;
|
||||||
|
option.textContent = value.Valore;
|
||||||
|
if (valToSelect && valToSelect === String(value.IdCustomFieldsValue)) {
|
||||||
|
option.selected = true;
|
||||||
|
}
|
||||||
|
dropdown.appendChild(option);
|
||||||
|
});
|
||||||
|
if (valToSelect) {
|
||||||
|
dropdown.value = valToSelect;
|
||||||
|
dropdown.dispatchEvent(new Event('change', {
|
||||||
|
bubbles: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2326,15 +2350,29 @@ function fixedDefaultValue(array $f): string
|
|||||||
results = await loadFixedFieldData(fieldKey);
|
results = await loadFixedFieldData(fieldKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
$select.select2('destroy').empty().select2({
|
if (results.length > 12) {
|
||||||
data: [{
|
// Select2 con ricerca
|
||||||
id: '',
|
$select.select2('destroy').empty().select2({
|
||||||
text: 'Seleziona...'
|
data: [{
|
||||||
}, ...results],
|
id: '',
|
||||||
placeholder: "Seleziona...",
|
text: 'Seleziona...'
|
||||||
allowClear: true,
|
}, ...results],
|
||||||
width: '100%'
|
placeholder: "Seleziona...",
|
||||||
});
|
allowClear: true,
|
||||||
|
width: '100%'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Select nativa senza Select2
|
||||||
|
try {
|
||||||
|
$select.select2('destroy');
|
||||||
|
} catch (e) {}
|
||||||
|
$select.empty();
|
||||||
|
$select.append(new Option('Seleziona...', '', true, false));
|
||||||
|
results.forEach(r => {
|
||||||
|
$select.append(new Option(r.text, r.id));
|
||||||
|
});
|
||||||
|
$select.css('width', '100%');
|
||||||
|
}
|
||||||
|
|
||||||
// Imposta valore iniziale
|
// Imposta valore iniziale
|
||||||
if (currentVal) {
|
if (currentVal) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user