-
Notifications
You must be signed in to change notification settings - Fork 25.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forms: update required validator when input is autofilled #30616
Comments
I came across this bug. It's terrible because it's random when it happens! Sometimes it shows up correctly, sometimes it does not. The ng-invalid and such classes are added to it, until the user clicks on the page. |
Any news on this issue ? related to : https://bugs.chromium.org/p/chromium/issues/detail?id=352527 and vuejs/vue#7058. We updated to last Angular 9.2 but the issue is still here. |
Yes, the issue still there, any news about it? Thanks. |
Hello. The issue is still there, and none of the hacks or patches found on internet works. This is really frustrating, as form button is shown to be disabled, because validation cannot read the text written to the input fields by the browser. |
I had a problem with FireFox 30.0 on iOS and its autocompletion-functionality for my login page. I implemented following workaround:
It takes the native values after 200ms and sets them into the reactive forms. |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
Why is it marked as feature? IMO it's a bug and shouldn't need votes to fix it. |
I'm not sure this is isolated to Chrome. I'm having similar issues in my iOS app packaged with Cordova. My login button is disabled based on form validity, which never changes despite the password manager having filled it in. I think I'm the 20th vote so hopefully the bot chills out |
@adamdport 21 votes is certainly plenty, I have attempted to silence the bot. On the one hand, this is clearly a nuisance, and many apps will want this to get nice validation behavior on login controls. But on the other hand, it's possible for apps to implement on their own, in the same manner as @angular/cdk I personally am leaning towards fixing inside the forms package, so I have pinned this on our FR triage board for further discussion at the next triage meeting. |
@dylhunn I'm unable to even get the value using Angular and was forced to resort to reading ionic-team/ionic-v3#928 |
@adamdport Interesting, that does seem to suggest the issue scope is more severe that we thought. This is just a guess, but I suspect it should be the same fix -- if I think the fix is to bring AutoFill detection into the core of the forms package, similar to how it's implemented in @angular/cdk |
We discussed this at great length in today's (Jul 29) team meeting. Here was the gist of our discussion:
|
@dylhunn Can you elaborate about it not working in all browsers? The |
We're using a different approach. We have our own directive which has to be set on input fields. There we listen to change event and set value to the FormControl, triggering validators that way. @UntilDestroy()
@Directive({
providers: [
{
provide: NgControl,
useExisting: forwardRef(() => AutoFillWorkaroundDirective )
}
],
selector: '[iosAutofill]'
})
export class AutoFillWorkaroundDirective implements AfterViewInit {
constructor(private elementRef: ElementRef, private ngControl: NgControl) {}
ngAfterViewInit(): void {
const element: HTMLElement = this.elementRef.nativeElement;
const input = element.querySelector('input');
if (!input) {
return;
}
fromEvent(input, 'change')
.pipe(untilDestroyed(this), debounceTime(100))
.subscribe(() => {
if (this.ngControl && this.ngControl.value !== input.value) {
this.ngControl.control?.setValue(input.value);
}
});
}
} |
Hi all! The Monkey patch solution from @kherock is coded in Angular 6, how are you fixing this issue recently? We have the issue with Chrome and Edge but not Firefox. Thank you! |
Hello. It's important to know the difference between autofill and autocomplete. Autofill: Automatically fill the form. (the form of autofill that affects us is the one that fills the form when the user visits the webpage). Important note before reading the actual explanation: I have tested this with Chrome because it's used by almost 65% of the users, it might be different with other browsers. AutofillIn the case of Autofill you can't do much because the data is not actually set in the input unless the user interacts with the webpage, this is why polling for values won't work. Edit: added an stackblitz to reproduce it, you will need to use the live webpage version instead of the editor version.
tip: you can visit the webpage a few times to make chrome offer the autocomplete. You have 3 options:
I would recommend option 2. AutocompleteIn this case a normal form implementation should work just fine because the user already interacted with the form. |
It was placebo effect, it still happens on chrome. Adapted the code to this problem. See angular/angular#30616 (comment)
So is there any solution or any working hack for ionic6. My ion-inputs are staying empty and form is not updated until touch aka focus happens on the one of the fields |
I modified @markusmo code and it seems to work well.
|
Nothing is helping. No matter whether u have a form or u use ngModel, whether u put all these directives floating around internet posts with autofillmonitor or with directives to react on input change. |
any updates about this issue? |
This is still an issue on Angular 14. Is there any kind of solution? |
Still a problem with chrome autofill, we are seeing it in production. |
I had this problem in chrome too and I got it working with AutoFillMonitor as mentioned before. To check if a submit button is disabled based on a required validation would be:
Note, this is a workaround, because I don't update the validation, and I don't have the autofilled value. But at least I get to disable properly, and when user interacts with the page (first click), validation is triggered. |
This issue still exists at July 2023. None of the workarounds above work. @markusmo @djwagner-cbc your solutions just does not work. Everything works only and only after the interaction with the page, e.g. by clicking somewhere on a page. |
Any news? Jan 2024 |
I'm not fully convinced it is Angular issue at all. If I load a page that Chrome autofills, select the input from dev console then $0.value is '' up until I press Enter after which it changes to the value prefilled by Chrome and also the app reacts expectedly. |
I don't know if it's a good practice but I use a workaround to tackle this problem, active focus in code var inputs = this.document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
inputs.item(i)!.focus();
}
inputs.item(0)!.focus(); Values are available after fields lose focus |
Amazing that this issue has been around for at least 6/7 years and still no fix! |
Now don't shoot me because we have a very big project, I am learning Angular and I may be missing the fact we have added a large import ie cdk, as someone says above can increase your project size, if anyone wants to update me why people don't like cdk that would be interesting. As, to resolve this autofill submit button issue i used this: ngAfterViewInit(){ with this on the button [disabled]="(loginForm.invalid || loggingIn) && notAutofilled" Is this a case that we have cdk so class 'cdk-text-field-autofilled' in our current project so I could hop on it and what you are all discussing is how to resolve this in forms when you aren't using excess modules etc. As I say I'm learning, so be kind :) |
Don't go down this rabbithole ... I already had a look at this and there hass been also a bug opened at Chrome, they closed it with the notion, that it is a Apple issue. Apple themselves pointed to Google and their implementation and also closed that ... |
For disabling/enabling the submit button, using |
🚀 feature request
Relevant Package
This feature request is for @angular/formsDescription
The
RequiredValidator
does not update its validation status when an input is autofilled in Chrome. This is problematic for users who set up a required username and password input and then conditionally enable the submit button when the inputs are valid. The user sees:This issue has been filed in the past on the components repo: angular/components#3414, though the change would really have to happen in @angular/forms.
Describe the solution you'd like
@angular/cdk has an
AutofillMonitor
that could be moved to @angular/forms and used to detect when an input is autofilled.Describe alternatives you've considered
It is possible to monkey patch a solution, as @kherock demonstrated on the components issue.
The text was updated successfully, but these errors were encountered: