Skip to content
Snippets Groups Projects
Commit 23378a87 authored by Pierre Ecarlat's avatar Pierre Ecarlat
Browse files

Merge branch 'bug/account/creation-wrong-validate-form' into 'dev'

(bug): Fix validateForm in account creation

See merge request !801
parents 99d78125 e51e7929
No related branches found
No related tags found
2 merge requests!805V3.0.1,!801(bug): Fix validateForm in account creation
......@@ -24,7 +24,7 @@
size="large"
type="password"
[value]="accountForm.get('password').value"
(valueChange)="accountForm.get('password').setValue($event)"
(valueChange)="accountForm.get('password').setValue($event); setValidationsForm()"
/>
<div class="special">
<p>Le mot de passe doit obligatoirement contenir :</p>
......
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { User } from '../../../models/user.model';
......@@ -11,28 +11,31 @@ import { accountFormStep } from './accountFormStep.enum';
selector: 'app-account-form',
templateUrl: './account-form.component.html',
})
export class AccountFormComponent implements OnChanges {
export class AccountFormComponent implements OnInit, OnChanges {
@Input() nbSteps: number;
@Input() currentStep: stepType;
@Input() accountForm: UntypedFormGroup;
@Input() isAccountMode: boolean;
public pagesValidation = [];
public userAcceptSavedDate = false;
public isPageValid: boolean;
public profile: User;
public accountFormStepEnum = accountFormStep;
public formType = formType;
@Output() pageValid = new EventEmitter<any>();
@Output() acceptNewsletter = new EventEmitter<any>();
@Output() pageValid = new EventEmitter<boolean>();
@Output() acceptNewsletter = new EventEmitter<boolean>();
constructor(private profileService: ProfileService) {}
ngOnInit(): void {
this.setValidationsForm();
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.currentStep) {
if (this.currentStep === accountFormStep.accountNewsletter) {
this.pageValid.emit();
}
if (changes.currentStep && this.pagesValidation.length > 0) {
this.updatePageValid();
}
}
public setValidationsForm(): void {
this.pagesValidation[accountFormStep.accountInfo] = {
valid:
......@@ -46,6 +49,12 @@ export class AccountFormComponent implements OnChanges {
this.accountForm.get('password').valid &&
this.accountForm.get('confirmPassword').valid,
};
this.pagesValidation[accountFormStep.accountNewsletter] = {
valid: true,
};
this.pagesValidation[accountFormStep.confirmEmailSentInfo] = {
valid: true,
};
this.updatePageValid();
}
......@@ -61,17 +70,9 @@ export class AccountFormComponent implements OnChanges {
}
}
/**
* Update valid page or return page validity of the given index
* @param {number} [index] - Page index
*/
private updatePageValid(index?: number): boolean {
if (index) {
return this.pagesValidation[index].valid;
}
this.isPageValid = this.pagesValidation[this.currentStep].valid;
if (this.isPageValid) this.pageValid.emit();
return this.isPageValid;
private updatePageValid(): void {
const isPageValid = this.pagesValidation[this.currentStep].valid;
this.pageValid.emit(isPageValid);
}
public acceptReceiveNewsletter(accept: boolean): void {
this.acceptNewsletter.emit(accept);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment