Skip to content
Snippets Groups Projects
Commit f606b9af authored by Mathias Chouet's avatar Mathias Chouet
Browse files

Fix bug: Alt+Enter triggers calculation even if form is invalid

parent ed8bb296
No related branches found
No related tags found
No related merge requests found
......@@ -330,19 +330,22 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
}
public doCompute() {
this.matomoTracker.trackEvent("userAction", "triggerCalculation", CalculatorType[this._formulaire.currentNub.calcType]);
this._formulaire.resetResults([]);
this.appComponent.showProgressBar = true;
this._computeClicked = true;
// send resetForm to clear log
this._formulaire.notifyObservers({
"action": "resetForm",
}, this._formulaire);
// calculate module
setTimeout(() => {
this._formulaire.doCompute();
this.appComponent.showProgressBar = false;
}, 100); // 100ms is important, a lower value may make the progress bar never appear :/
// check again, to prevent Alt+Enter to calculate an invalid form
if (! this.isCalculateDisabled) {
this.matomoTracker.trackEvent("userAction", "triggerCalculation", CalculatorType[this._formulaire.currentNub.calcType]);
this._formulaire.resetResults([]);
this.appComponent.showProgressBar = true;
this._computeClicked = true;
// send resetForm to clear log
this._formulaire.notifyObservers({
"action": "resetForm",
}, this._formulaire);
// calculate module
setTimeout(() => {
this._formulaire.doCompute();
this.appComponent.showProgressBar = false;
}, 100); // 100ms is important, a lower value may make the progress bar never appear :/
}
}
public onCalcResultsViewChecked() {
......@@ -439,49 +442,50 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
private updateUIValidity() {
this._isUIValid = false;
if (! this._formulaire.calculateDisabled) {
if (this._fieldsetComponents !== undefined) {
this._isUIValid = this._fieldsetComponents.reduce(
// callback
(
// accumulator (valeur précédente du résultat)
acc,
// currentValue (élément courant dans le tableau)
fieldset,
// currentIndex (indice courant dans le tableau)
currIndex,
// array (tableau parcouru)
array
) => {
return acc && fieldset.isValid;
}
// valeur initiale
, this._fieldsetComponents.length > 0);
}
if (this._fieldsetContainerComponents !== undefined) {
this._isUIValid = this._isUIValid && this._fieldsetContainerComponents.reduce<boolean>(
// callback
(
// accumulator (valeur précédente du résultat)
acc,
// currentValue (élément courant dans le tableau)
fieldsetContainer,
// currentIndex (indice courant dans le tableau)
currIndex,
// array (tableau parcouru)
array
): boolean => {
return acc && fieldsetContainer.isValid;
}
// valeur initiale
, true);
}
if (this._pabTableComponent !== undefined) {
this._isUIValid = this._isUIValid && this._pabTableComponent.isValid;
// all fieldsets must be valid
if (this._fieldsetComponents !== undefined) {
this._isUIValid = this._fieldsetComponents.reduce(
// callback
(
// accumulator (valeur précédente du résultat)
acc,
// currentValue (élément courant dans le tableau)
fieldset,
// currentIndex (indice courant dans le tableau)
currIndex,
// array (tableau parcouru)
array
) => {
return acc && fieldset.isValid;
}
// valeur initiale
, this._fieldsetComponents.length > 0);
}
// all fieldset containers must be valid
if (this._fieldsetContainerComponents !== undefined) {
this._isUIValid = this._isUIValid && this._fieldsetContainerComponents.reduce<boolean>(
// callback
(
// accumulator (valeur précédente du résultat)
acc,
// currentValue (élément courant dans le tableau)
fieldsetContainer,
// currentIndex (indice courant dans le tableau)
currIndex,
// array (tableau parcouru)
array
): boolean => {
return acc && fieldsetContainer.isValid;
}
// valeur initiale
, true);
}
// special components must be valid
if (this._pabTableComponent !== undefined) {
this._isUIValid = this._isUIValid && this._pabTableComponent.isValid;
}
}
}
}
public getElementStyleDisplay(id: string) {
const isDisplayed: boolean = this._formulaire.isDisplayed(id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment