samedi 25 août 2018

Ionic Angular Validator Pattern

I am trying to prevent the user from typing symbols and emojis on the keyboard, for this I am using the pattern validator, but when I type something in the input, this appears

can not read property 'required' of null

how to solve this?

   <form [formGroup]="instituicao">
     <p>Informe os dados:</p>
      <ion-item>
        <ion-label stacked>ONG:</ion-label>
        <ion-input type="text" formControlName="ong"></ion-input>
      </ion-item>
      <ion-item *ngIf="!instituicao.controls.ong.valid & 
      (instituicao.controls.ong.dirty || instituicao.controls.ong.touched)">
      <div [hidden]="!instituicao.controls.ong.errors.required">
        O campo é obrigatório
      </div>
    </ion-item>
    <ion-item text-center *ngIf="
      instituicao.controls.ong.valid">
      <div [hidden]="
        !instituicao.controls.ong.valid">
        <button ion-button outline large color="danger" 
          (click)="createAccount()">Cadastrar</button>
      </div>
      </ion-item>
   </form>

import { FormBuilder, FormGroup, Validators } from '@angular/forms';

createForm() {
    this.instituicao = this.formBuilder.group({
      key: [this.instituicao_array.key, Validators.required],
      ong: [this.instituicao_array.ong,Validators.required, Validators.pattern('[a-zA-Z ]*')]
    })
  }

Aucun commentaire:

Enregistrer un commentaire