<ion-header>
    <ion-toolbar>
      <ion-title>Change Password</ion-title>
    </ion-toolbar>
  </ion-header>
  
  <ion-content>
    <form #form="ngForm" (ngSubmit)="change(form)" [formGroup]="matching_passwords_group">
      <ion-grid>
        <ion-row color="primary" justify-content-center>
          <ion-col align-self-center size-md="6" size-lg="5" size-xs="12">
            <div text-center>
              <h3>Change Password</h3>
            </div>
            <div padding>
              <ion-item>
                <ion-input formControlName="oldpassword" type="password" placeholder="old password" ngModel required></ion-input>
              </ion-item>
              <ion-item>
                <ion-input formControlName="newpassword" type="password" placeholder="new password" ngModel required></ion-input>
              </ion-item>
              <ion-item>
                <ion-input formControlName="newpasswordbis" type="password" placeholder="repeat new password" ngModel required></ion-input>
              </ion-item>
            </div>
            <div padding>
              <ion-button size="large" type="submit" [disabled]="form.invalid" expand="block">Reset Password</ion-button>
            </div>
          </ion-col>
        </ion-row>
        <ion-row color="primary" justify-content-center>
          <div class="validation-errors" justify-content-center>
            <ng-container *ngFor="let validation of validation_messages.newpassword">
              <div class="error-message" *ngIf="matching_passwords_group.get('newpassword').hasError(validation.type) && (matching_passwords_group.get('newpassword').dirty 
              || matching_passwords_group.get('newpassword').touched)">
                {{ validation.message }}
              </div>
            </ng-container>
            <ng-container *ngFor="let validation of validation_messages.newpasswordbis">
              <div class="error-message" *ngIf="matching_passwords_group.get('newpasswordbis').hasError(validation.type) && (matching_passwords_group.get('newpasswordbis').dirty 
              || matching_passwords_group.get('newpasswordbis').touched)">
                {{ validation.message }}
              </div>
            </ng-container>
            <ng-container *ngFor="let validation of validation_messages.newpasswordbis">
              <div class="error-message" *ngIf="matching_passwords_group.hasError('areEqual')">
                {{ validation.message }}
              </div>
            </ng-container>
          </div>
        </ion-row>
      </ion-grid>
    </form>    
  </ion-content>