Fix the checkbox disable logic, and call the function on page load

This commit is contained in:
Rosemary Orchard 2022-04-18 10:32:50 +01:00
parent 40721aa421
commit 277dbc47c0

View File

@ -247,14 +247,13 @@ $('#default_consume_location_id').change(function(event) {
function updateMoveOnOpen() { function updateMoveOnOpen() {
var defaultLocation = $("#location_id :selected").val(); var defaultLocation = $("#location_id :selected").val();
var consumeLocationLocation = document.getElementById('default_consume_location_id'); var consumeLocationLocation = $("#default_consume_location_id :selected").val();
var moveOnOpen = document.getElementById('move_on_open'); if (!consumeLocationLocation || defaultLocation === consumeLocationLocation) {
if (consumeLocationLocation && defaultLocation !== consumeLocationLocation) { document.getElementById("move_on_open").checked = false;
moveOnOpen.removeAttribute('checked'); $("#move_on_open").attr("disabled", true);
moveOnOpen.setAttribute('disabled', "");
} else { } else {
moveOnOpen.removeAttribute('disabled'); $("#move_on_open").attr("disabled", false);
} }
} }
@ -573,6 +572,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
}); });
updateMoveOnOpen();
Grocy.FrontendHelpers.ValidateForm("product-form"); Grocy.FrontendHelpers.ValidateForm("product-form");
Grocy.Components.ProductPicker.GetPicker().trigger("change"); Grocy.Components.ProductPicker.GetPicker().trigger("change");