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;
|
||||
}
|
||||
|
||||
dropdown.innerHTML = '<option value="">Seleziona...</option>';
|
||||
dropdownData[fieldId].forEach(value => {
|
||||
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);
|
||||
});
|
||||
const items = dropdownData[fieldId];
|
||||
const valToSelect = currentValue || selectedValue;
|
||||
|
||||
// Ripristina il valore corrente
|
||||
if (currentValue || selectedValue) {
|
||||
dropdown.value = currentValue || selectedValue;
|
||||
const event = new Event('change', {
|
||||
bubbles: true
|
||||
if (items.length > 12) {
|
||||
// Select2 con ricerca
|
||||
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);
|
||||
});
|
||||
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);
|
||||
}
|
||||
|
||||
$select.select2('destroy').empty().select2({
|
||||
data: [{
|
||||
id: '',
|
||||
text: 'Seleziona...'
|
||||
}, ...results],
|
||||
placeholder: "Seleziona...",
|
||||
allowClear: true,
|
||||
width: '100%'
|
||||
});
|
||||
if (results.length > 12) {
|
||||
// Select2 con ricerca
|
||||
$select.select2('destroy').empty().select2({
|
||||
data: [{
|
||||
id: '',
|
||||
text: 'Seleziona...'
|
||||
}, ...results],
|
||||
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
|
||||
if (currentVal) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user