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