Skip to content

Commit

Permalink
fix(stock): submit button active only when valid
Browse files Browse the repository at this point in the history
This commit ensures the submit button on the exit module is only active
when the form is valid for submission.  Previously, there was a corner
case where we would enable the submit button after a date change,
despite not having valid data.

Partially addresses #5425.
  • Loading branch information
jniles committed Mar 3, 2021
1 parent 29fa30e commit 05e5887
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions client/src/modules/stock/exit/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function StockExitController(
vm.dateMessageWarning = true;
}
loadInventories(vm.depot, date);
checkValidity();
};

vm.onChangeDepot = depot => {
Expand Down Expand Up @@ -264,9 +265,10 @@ function StockExitController(

function loadInventories(depot, dateTo = new Date()) {
setupStock();

vm.loading = true;
Stock.inventories.read(null, { depot_uuid : depot.uuid, dateTo })
.then(inventories => {
vm.loading = false;
vm.selectableInventories = inventories.filter(item => item.quantity > 0);

// Here we check directly if a Depot has inventories in stock available
Expand All @@ -276,7 +278,10 @@ function StockExitController(
vm.mapSelectableInventories = new Store({ identifier : 'inventory_uuid', data : vm.selectableInventories });
checkValidity();
})
.catch(Notify.handleError);
.catch(Notify.handleError)
.finally(() => {
vm.loading = false;
});
}

// on lot select
Expand Down Expand Up @@ -306,7 +311,8 @@ function StockExitController(
const lotsExists = vm.stockForm.store.data.every(item => {
return item.quantity > 0 && item.lot.uuid;
});
vm.validForSubmit = (lotsExists && vm.stockForm.store.data.length);

vm.validForSubmit = (lotsExists && vm.stockForm.store.data.length && !vm.loading);
}

function handleSelectedEntity(_entity, _type) {
Expand Down Expand Up @@ -461,13 +467,10 @@ function StockExitController(
}

vm.$loading = true;
return mapExit[vm.movement.exit_type].submit(form)
.then(toggleLoadingIndicator)
.catch(Notify.handleError);
}

function toggleLoadingIndicator() {
vm.$loading = !vm.$loading;
return mapExit[vm.movement.exit_type].submit(form)
.catch(Notify.handleError)
.finally(() => { vm.$loading = false; });
}

function reinit(form) {
Expand Down

0 comments on commit 05e5887

Please sign in to comment.