Search code examples
htmlformsgoogle-chromeautocompleteautofill

Chrome Autofill triggering separately for billing and contact information


Autofill is triggering separately for billing and for contact information.

For example, when I click on any of the following 4 input fills it offers autofill for them => first name, last name, phone number and email. When I click on any of the following 4 it triggers autofill for them together => billing address, billing postal-code, billing country, billing city.

Autofill works well for each of the two groups, but I want it to be one group that will autofill by selecting any of the 8 input fields.

Code example (I'm using Angular 8 with Material design components but I think this shouldn't pose as a distraction since I see this as a HTML issue):

<form method="post" id="paymentForm" [formGroup]="formGroup" (ngSubmit)="onSubmit(formGroup.value)" class="form" >

    <div class="customer-info">
        <div class="customer-info-personal">
            <div>
                <mat-form-field class="form-element">
                    <input name="fname" matInput placeholder="Ime" formControlName="firstName" autocomplete="given-name" form="paymentForm">
                    <mat-error
                        *ngIf="!formGroup.controls['firstName'].valid && formGroup.controls['firstName'].touched">
                    </mat-error>
                </mat-form-field>
                <mat-form-field class="form-element">
                    <input name="lname" matInput placeholder="Prezime" formControlName="lastName" autocomplete="family-name" form="paymentForm">
                    <mat-error *ngIf="!formGroup.controls['lastName'].valid && formGroup.controls['lastName'].touched">
                    </mat-error>
                </mat-form-field>
                
                <mat-form-field class="form-element">
                    <input name="bill-address" matInput placeholder="Adresa" formControlName="billingAddress" autocomplete="billing street-address" form="paymentForm">
                    <mat-error *ngIf="!formGroup.controls['billingAddress'].valid && formGroup.controls['billingAddress'].touched">
                    </mat-error>
                </mat-form-field>

                <mat-form-field class="form-element">
                    <input name="bill-city" matInput placeholder="Grad" formControlName="billingCity" autocomplete="billing address-level2" form="paymentForm">
                    <mat-error *ngIf="!formGroup.controls['billingCity'].valid && formGroup.controls['billingCity'].touched">
                    </mat-error>
                </mat-form-field>
            </div>
            <div>
                <mat-form-field class="form-element">
                    <input name="bill-zip" matInput placeholder="Poštanski broj" formControlName="billingPostalNumber" autocomplete="billing postal-code" form="paymentForm">
                    <mat-error
                        *ngIf="!formGroup.controls['billingPostalNumber'].valid && formGroup.controls['billingPostalNumber'].touched">
                    </mat-error>
                </mat-form-field>
                <mat-form-field class="form-element">
                    <input name="bill-country" matInput placeholder="Država" formControlName="billingCountry" autocomplete="billing country" form="paymentForm">
                    <mat-error *ngIf="!formGroup.controls['billingCountry'].valid && formGroup.controls['billingCountry'].touched">
                    </mat-error>
                </mat-form-field>
                <mat-form-field class="form-element">
                    <input name="email" matInput placeholder="e-mail" formControlName="email" autocomplete="email" type="email" form="paymentForm">
                    <mat-error *ngIf="!formGroup.controls['email'].valid && formGroup.controls['email'].touched">
                    </mat-error>
                </mat-form-field>
                <mat-form-field class="form-element">
                    <input name="phone" matInput placeholder="Broj telefona" formControlName="phoneNumber" autocomplete="tel" type="tel" form="paymentForm">
                    <mat-error
                        *ngIf="!formGroup.controls['phoneNumber'].valid && formGroup.controls['phoneNumber'].touched">
                    </mat-error>
                </mat-form-field>
            </div>

        </div>
        <div class="buttons-element">
            <div class="pay-button-element">
                <button mat-raised-button color="primary" type="submit" class="button"
                    [disabled]="!formGroup.valid">Plati</button>
            </div>
            <div class="cancel-button-element">
                <button mat-button color="secondary" type="submit" class="button">Odustani</button>
            </div>
        </div>
    </div>
</form> ```

Solution

  • Fixed it by removing the word billing from autocomplete values and bill- from name values.

    E.g.

    Before autocomplete="billing postal-code" name="zip"

    Before autocomplete="postal-code" name="zip"

    Changing the autocomplete field alone proved to be enough.