简体   繁体   English

当我尝试单击密码显示和隐藏图标时,所有表单字段都显示验证

[英]when i try to click on pasword show & hide icon then all form fields are showing validation

<pre>

    <mat-form-field>
          <mat-label>Enter your password</mat-label>
          <input
            matInput
            [type]="hide ? 'password' : 'text'"
            formControlName="password"
            required
          />
          <button
            mat-icon-button
            matSuffix
            (click)="hide = !hide"
            [attr.aria-label]="'Hide password'"
            [attr.aria-pressed]="hide"
          >
            <mat-icon>{{ hide ? "visibility_off" : "visibility" }}</mat-icon>
          </button>
          <mat-error
            *ngIf="
              registerForm.get('password').hasError('minlength') &&
              registerForm.get('password').hasError('required')
            "
            >Password must have at least 8 characters</mat-error
          >
        </mat-form-field>
</pre>

ts file .ts 文件

    export class RegisteruserComponent implements OnInit {
      hide = true;
      isLoad = false;
      registerForm = this.formbuilder.group(
        {
          name: [null],
          email: [
            null,
            Validators.compose([
              Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$'),
            ]),
          ],
          password: [
            null,
            Validators.compose([
              Validators.required,
              Validators.minLength(5),
              Validators.maxLength(5),
            ]),
          ],
          confirmPassword: ['', Validators.required],
        },
        { validators: passwordMatchValidator }
      );
      constructor(private formbuilder: FormBuilder) {}
      ngOnInit(): void {}
      // tslint:disable-next-line: typedef
      /* Called on each input in either password field */
      // tslint:disable-next-line: typedef
      confirmPassword() {
        return this.registerForm.hasError('passwordMismatch')
          ? this.registerForm.controls.confirmPassword.setErrors([
              { passwordMismatch: true },
       

     ])
      : this.registerForm.controls.confirmPassword.setErrors(null);
  }
  // tslint:disable-next-line: typedef
  onSubmit() {
    // tslint:disable-next-line: no-debugger
    debugger;
    console.log(this.registerForm);
  }
}

When i try to hide & show the password icon it's hide & show working properly but the issue is total form also showing validation border color is highlighting, can any one help me on this When i try to hide & show the password icon it's hide & show working properly but the issue is total form also showing validation border color is highlighting, can any one help me on this当我尝试隐藏和显示密码图标时,它的隐藏和显示工作正常,但问题是整个表单还显示验证边框颜色突出显示,任何人都可以帮助我解决这个问题当我尝试隐藏和显示密码图标时,它是隐藏和显示工作正常,但问题是整个表单也显示验证边框颜色突出显示,任何人都可以帮助我

Try to add button type = button尝试添加按钮类型 = 按钮

<button     type="button"
            mat-icon-button
            matSuffix
            (click)="hide = !hide"
            [attr.aria-label]="'Hide password'"
            [attr.aria-pressed]="hide"
          >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击隐藏和显示的切换时,表单字段将生效 - Form fields are validating on click of toggle for hide and show 单击按钮时,我想隐藏和显示输入字段 - I want to hide and show input fields when click on a button 当我单击隐藏和显示按钮时,提交了两次表单 - Two times form submitted, when I click the hide and show button 当我只有一个字段时,需要表格来检查所有字段以进行验证 - Need form to check all fields for validation when I only one field setValue数据未显示在表单字段中,当我编辑列表项时 - setValue data not showing in form fields, When i edit a list item 当我点击图标时,Ionic Angular 侧边菜单不显示 - Ionic Angular side-menu doesn't show up when I click on the icon 隐藏或显示传输图标 - Hide or Show Transfer Icon Angular 4如何显示隐藏的嵌套表单组验证 - Angular 4 how to show hide nested Form Group validation 如何在悬停或单击时显示图标,再次用鼠标将其隐藏或使用ngFor angular 7单击其他列表 - How to show an icon on hover or click, again hide it on mouse out or click other list with ngFor angular 7 使用Angular。当我点击链接时,我想打开新页面显示,链接下方不显示 - Using Angular.When I click the link, I want to open the new page to show, not showing below the link
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM