Improve free price input auto-checking/selecting items and addons

This commit is contained in:
Richard Schreiber
2022-06-15 13:25:31 +02:00
committed by GitHub
parent dfebcf5294
commit 979e02ec73
3 changed files with 34 additions and 3 deletions

View File

@@ -650,11 +650,22 @@ $(function () {
// Lightbox
lightbox.init();
// free-range price input auto-check checkbox
// free-range price input auto-check checkbox/set count-input to 1 if 0
$("[data-checked-onchange]").each(function() {
var checkbox = this;
var countInput = this;
$("#" + this.getAttribute("data-checked-onchange")).on("change", function() {
checkbox.checked = true;
if (countInput.type === "checkbox") {
if (countInput.checked) return;
countInput.checked = true;
}
else if (countInput.type === "number" && !countInput.valueAsNumber) {
countInput.value = "1";
}
else {
return;
}
// in case of a change, trigger event
$(countInput).trigger("change");
});
});
});