added select 2 on capitolato
This commit is contained in:
parent
b562eb4033
commit
223688c372
@ -307,4 +307,23 @@
|
|||||||
width: 250px !important;
|
width: 250px !important;
|
||||||
min-width: 250px !important;
|
min-width: 250px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#partsTableBody .extra-field-td .select2-container {
|
||||||
|
width: 100% !important;
|
||||||
|
min-width: 180px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTableBody .extra-field-td .select2-selection--single {
|
||||||
|
height: 31px !important;
|
||||||
|
padding: 0.15rem 0.35rem !important;
|
||||||
|
border: 1px solid #ced4da !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTableBody .extra-field-td .select2-selection__rendered {
|
||||||
|
line-height: 28px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#partsTableBody .extra-field-td .select2-selection__arrow {
|
||||||
|
height: 29px !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -136,6 +136,50 @@ $(document).ready(function () {
|
|||||||
</td>`;
|
</td>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initializeExtraFieldSelect2($context) {
|
||||||
|
if (typeof $.fn.select2 === "undefined") return;
|
||||||
|
|
||||||
|
$context.find(".part-extra-select").each(function () {
|
||||||
|
const $select = $(this);
|
||||||
|
|
||||||
|
if ($select.hasClass("select2-hidden-accessible")) {
|
||||||
|
$select.select2("destroy");
|
||||||
|
}
|
||||||
|
|
||||||
|
$select.select2({
|
||||||
|
placeholder: "Seleziona...",
|
||||||
|
allowClear: true,
|
||||||
|
width: "100%",
|
||||||
|
dropdownParent: $("#partsModal"),
|
||||||
|
minimumResultsForSearch: 0,
|
||||||
|
sorter: function (data) {
|
||||||
|
return data.sort(function (a, b) {
|
||||||
|
const textA = (a.text || "").toLowerCase();
|
||||||
|
const textB = (b.text || "").toLowerCase();
|
||||||
|
return textA.localeCompare(textB, "it", {
|
||||||
|
sensitivity: "base",
|
||||||
|
numeric: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
matcher: function (params, data) {
|
||||||
|
if ($.trim(params.term) === "") return data;
|
||||||
|
if (typeof data.text === "undefined") return null;
|
||||||
|
|
||||||
|
const term = params.term.toLowerCase();
|
||||||
|
const text = data.text.toLowerCase();
|
||||||
|
|
||||||
|
return text.indexOf(term) > -1 ? data : null;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const selected = ($select.attr("data-selected") || "").toString();
|
||||||
|
if (selected) {
|
||||||
|
$select.val(selected).trigger("change.select2");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).on("change", ".part-extra-select", function () {
|
$(document).on("change", ".part-extra-select", function () {
|
||||||
const valId = $(this).val() || "";
|
const valId = $(this).val() || "";
|
||||||
const $row = $(this).closest("tr");
|
const $row = $(this).closest("tr");
|
||||||
@ -173,13 +217,14 @@ $(document).ready(function () {
|
|||||||
const $row = $(this);
|
const $row = $(this);
|
||||||
$row.find("td:last").before(buildExtraFieldCellHtml($row));
|
$row.find("td:last").before(buildExtraFieldCellHtml($row));
|
||||||
|
|
||||||
// ripristina selezione se già presente nello stato riga
|
|
||||||
const selected = ($row.data("extra-value-id") || "").toString();
|
const selected = ($row.data("extra-value-id") || "").toString();
|
||||||
if (selected) {
|
if (selected) {
|
||||||
$row.find(".part-extra-value-id").val(selected);
|
$row.find(".part-extra-value-id").val(selected);
|
||||||
$row.find(".part-extra-select").val(selected);
|
$row.find(".part-extra-select").attr("data-selected", selected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
initializeExtraFieldSelect2($("#partsTableBody"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPartId($row, id) {
|
function setPartId($row, id) {
|
||||||
@ -911,9 +956,13 @@ $(document).ready(function () {
|
|||||||
</td>
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
$("#partsTableBody").append(newRow);
|
$("#partsTableBody").append(newRow);
|
||||||
const $select = $("#partsTableBody tr:last .part-matrice");
|
const $newRow = $("#partsTableBody tr:last");
|
||||||
|
const $select = $newRow.find(".part-matrice");
|
||||||
const selectedMacro = $("#macro-matrice-filter").val() || "";
|
const selectedMacro = $("#macro-matrice-filter").val() || "";
|
||||||
|
|
||||||
initializeSelect2($select, nextPartNumber, "", null, selectedMacro);
|
initializeSelect2($select, nextPartNumber, "", null, selectedMacro);
|
||||||
|
initializeExtraFieldSelect2($newRow);
|
||||||
|
|
||||||
updateRowButtons();
|
updateRowButtons();
|
||||||
markUnsaved();
|
markUnsaved();
|
||||||
}
|
}
|
||||||
@ -1416,8 +1465,14 @@ $(document).ready(function () {
|
|||||||
const vid = String(part.extra_value_id);
|
const vid = String(part.extra_value_id);
|
||||||
$row.data("extra-value-id", vid);
|
$row.data("extra-value-id", vid);
|
||||||
$row.find(".part-extra-value-id").val(vid);
|
$row.find(".part-extra-value-id").val(vid);
|
||||||
$row.find(".part-extra-select").val(vid);
|
$row.find(".part-extra-select").attr(
|
||||||
|
"data-selected",
|
||||||
|
vid,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializeExtraFieldSelect2($row);
|
||||||
|
|
||||||
const $select = $("#partsTableBody").find(
|
const $select = $("#partsTableBody").find(
|
||||||
`tr[data-part-id="${part.id}"] .part-matrice`,
|
`tr[data-part-id="${part.id}"] .part-matrice`,
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user