Angular 2-浏览器自动填充时,表单无效 [英] Angular 2 - Form is invalid when browser autofill

查看:201
本文介绍了Angular 2-浏览器自动填充时,表单无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含电子邮件和密码字段的登录表单.

I have a Login Form which has email and password fields.

我选择了自动填充浏览器.

I've chosen for browser autofill.

问题是:当浏览器自动填写登录表单时,两个字段都是原始且未更改的,因此禁用了提交按钮.

The problems is: When browser autofills login form, both fields are pristine and untouched, so the submit button is disabled.

如果我单击禁用"按钮,它将启用并触发提交操作,这很好.但是默认的禁用方面非常糟糕,这会使某些用户感到失望.

If I click on disabled button, it enables and fires submit action, what is nice. But the default disabled aspect is pretty bad what can make some users disappointed.

您对如何处理有一些想法吗?

Do you have some ideas about how to deal with?

推荐答案

我使用ChangeDetectorRef提供程序解决了此问题.
只需手动检查detectChanges(),然后再检查输入是否有效.

I solved this problem with the ChangeDetectorRef Provider.
Simply do a manual detectChanges() before you check if the input is valid.

如果单击按钮后仍无法检查,请在事件绑定为(input)=changedetectorfunc()的输入元素的Input-Event上进行监听,并在此函数中调用changeDetector.
因此必须正常工作.
希望,对您有帮助.

If you aren't able to check after a button click, then hear on the Input-Event of the Input-Element with the event-binding (input)=changedetectorfunc() and call the changeDetector in this function.
Therefore it must work.
Hope, it helps you.

有用的链接:

  • https://angular.io/api/core/ChangeDetectorRef
  • Angular 2 change event on every keypress

最美好的祝愿

这篇关于Angular 2-浏览器自动填充时,表单无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆