Skip to content
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

mat-autocomplete value not updating with browser autofill #9704

Closed
leveyh opened this issue Jan 30, 2018 · 5 comments · Fixed by #9887
Closed

mat-autocomplete value not updating with browser autofill #9704

leveyh opened this issue Jan 30, 2018 · 5 comments · Fixed by #9887
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@leveyh
Copy link

leveyh commented Jan 30, 2018

Bug, feature request, or proposal:

Bug.

What is the expected behavior?

FormControl value should change when using browser autofill to complete the address.

What is the current behavior?

FormControl value does not change. Validation fails on the field.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-autocomplete-with-autofill

Start typing in the Name field. Use browser autofill to automatically fill out the rest of the form.

It seems as though the "Address line 1" field, which is controlled by a mat-autocomplete, fails to update after autofill, causing validation to fail.

autofill

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 5.2.1
Material: 5.1.0
Browser: Chrome 64.0.3282.119

@mmalerba
Copy link
Contributor

@crisbeto assigning to you since this seems specific to the autocomplete

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr labels Feb 11, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Feb 11, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes angular#9704.
crisbeto added a commit to crisbeto/material2 that referenced this issue Feb 12, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes angular#9704.
@Rawr421
Copy link

Rawr421 commented May 7, 2018

I also have this problem with:
Angular 6.0.0
Material: 6.0.1

Form control validation is failing on address_line1 when autofill is used.
screen shot 2018-05-07 at 4 36 27 pm

Also, autofill is not updating the filtered values, because the control value is not updated.
screen shot 2018-05-07 at 4 37 58 pm

mmalerba pushed a commit that referenced this issue May 24, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
andrewseguin pushed a commit that referenced this issue Jun 7, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 30, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes angular#9704.
@ReallyNotARussianSpy
Copy link

I also have this problem. My form control's value is not updating after a browser autofill and it is causing my validation to not work for autocomplete with control's set to updateOn: 'blur'

document.getElementById('input-email')['value']; // "email@example.com"
this.loginForm.get('email').value; // ""

Angular 6.1.3
Angular Material 6.4.5

Thanks!

jelbourn pushed a commit that referenced this issue Aug 23, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
jelbourn pushed a commit that referenced this issue Aug 25, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
@daniel-nagy
Copy link

For anyone else, I'm using the following workaround

import { Component, Inject, ViewChild } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { MatAutocompleteTrigger } from '@angular/material';

@Component({
  ...
  template: `
    <input
      autocomplete="address-level1"
      (input)="onInput($event)"
      [matAutocomplete]="myAutocomplete"
      matInput
      #myAutocompleteTrigger="matAutocompleteTrigger">
      <mat-autocomplete #myAutocomplete="matAutocomplete">
        ...
      </mat-autocomplete>
  `
})
export class MyComponent {
  @ViewChild('myAutocompleteTrigger') private _myAutocompleteTrigger: MatAutocompleteTrigger;

  constructor(@Inject(DOCUMENT) private _document: Document) {

  }

  onInput = (event: KeyboardEvent) => {
    const target = event.currentTarget as HTMLInputElement;

    if (this._document.activeElement !== target) {
      this._myAutocompleteTrigger._onChange(target.value);
    }
  }
}

vivian-hu-zz pushed a commit that referenced this issue Oct 3, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 13, 2018
… form control

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes angular#9704.
andrewseguin pushed a commit that referenced this issue Nov 14, 2018
… form control (#9887)

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
josephperrott pushed a commit that referenced this issue Nov 19, 2018
… form control (#9887)

Currently we skip any `input` events on an autocomplete trigger that have been dispatched while the element is blurre, in order to handle some IE-specific cases. This ends up preventing the autocomplete from picking up any changes to its value that have come as a result of the browser autofill. These changes move some logic around to handle both autofilling and the IE issues.

Fixes #9704.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
6 participants