私のエラーメッセージが壊れてしまった理由を知りませんでした。 type = "number"や有効なhtmlタイプの属性を追加しても、エラーメッセージ(minLengthまたはmaxLengthがトリガーされず他のものはテストされていない)がトリガーされないことが判明しました。入力タイプの属性が角の形を壊すバリデータ
コンポーネント:
createForm() {
this.shortForm = this.fb.group({
firstName: ['', [Validators.required, Validators.minLength(1), Validators.maxLength(50) ]],
lastName: ['', [Validators.required, Validators.minLength(1), Validators.maxLength(50)]],
primaryAddrZip: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(5)] ]
})
テンプレート:
<md-input-container>
<input
type="number"
formControlName="primaryAddrZip"
mdInput placeholder="Zip code"
data-testing="zip"
(keypress)="numbersOnlyValidation($event, 'zip'); maxLength($event, 5)"
(paste)="$event.preventDefault()"
>
<md-error data-testing="zip-req" *ngIf="shortForm.get('primaryAddrZip').hasError('required') && shortForm.get('primaryAddrZip').touched">
Zip code is required
</md-error>
<md-error data-testing="zip-min-five-digits" *ngIf="shortForm.get('primaryAddrZip').hasError('minlength') && shortForm.get('primaryAddrZip').touched">
Minimum of 5 characters . <!--WILL NOT TRIGGER-->
</md-error>
</md-input-container>
これは既知のバグまたは私は間違ってバリデータを使用していますか?
フォームビルダーでは、primaryAddrZipに文字列(primaryAddrZip:['' ......)を定義しました。数字を変更することはできますか? – Rama
まだ材料に実装されていません – Aravind
@Ramaどのように番号に変更しますか?小括弧の後の単一引用符は、フォームフィールドの値用です。おもう? – Anthony