Datalist element, possible to autofill multiple inputs? - html

I'm working on a datalist element to populate same fields with information about a location (Address, state, city, zip code, etc.) I noticed that Chrome can autofill multiple fields with a selection from it's pre-saved addresses that have been entered before, using an entry form one field's datalist. What I'm wondering is if it's possible for me to create options that take advantage of some browser behavior to fill multiple fields myself, or if this will need to be done programmatically. I'll post a little example snippet to try to make it more clear about what I want to do:
<input type='text' name='address' list='address-suggestions' />
<datalist id='address-suggestions'>
<option>123 Example Address Rd., New York City, NY 10001</option>
</datalist>
<input type='text' name='city' />
<input type='text' name='state' />
<input type='text' name='zip-code' />
My goal is to fill in all four fields with the option available in the datalist I'm quite confident I can do it programmatically, but given that I'm seeing Chrome do it natively, I was wondering if there was some functionality I was unaware of / had not been able to find information about elsewhere.

Yes it's possible but not all browsers behave the same.
The MDN Docs should provide some help if your using the autocomplete HTML Attribute. It should allow you better control of what gets autofilled and what doesn't.

Related

How do I disable or prevent input text suggestions for form fields in Edge?

How do I prevent a form from suggesting auto-complete values, from previous entries or from saved information in Edge?
In the above image, the email input field is marked as autocomplete="false", but still in the right pane you can see the suggestion is populating.
When I add autocomplete=disabled to one field it seems it work, but when I add the attribute to all the inputs, it again starts displaying suggestions for every field.
What is the solution for this?
Add the aria-autocomplete="list" attribute to the input.
<input type="text" id="FirstName" name="attr1" aria-autocomplete="list">
Do not use any other value for the attribute.
According to your description, I reproduced the problem. I think your issue is caused by the "Save and fill personal info" setting being enabled in Edge.
If you navigate to edge://settings/personalinfo and disable this feature, you can see this behavior no longer exists.
Or you can also click the "Manage personal info" option in the picture you provided, and then disable it.
I did some simple tests and found that if you need to solve the problem from the code, you need to modify the name attribute of the form's related field.
Like this(do not use attribute values like name or email... and maybe there are others I am not aware of):
<label for="attr1">attr1:</label>
<input type="text" id="FirstName" name="attr1">
<label for="attr2">attr2 :</label>
<input type="text" id="LastName" name="attr2">
<label for="attr3">attr3 :</label>
<input type="email" id="Email" name="attr3" autocomplete="off">
<input type="submit">
I don't recommend this, because good naming helps you understand and maintain the code. Using proper attributes like name and email also helps your code be more accessible for screen readers or other assistive technology.

Chrome autofill credit card in input without name or autofill attributes

Lately, we have added a custom React components library to our app (company standart). It has a limitation - doesn't allow to set name or autocomplete attribute. So, some of our inputs lost name attribute after an update.
After update our rendered input looks like this:
<div class="search-input">
<div class="sc-bYwzuL dnjiBM">
<input data-test-id="navigation_customer-search-input" placeholder="Search for a customer" rows="1" value="">
</div>
</div>
And Chrome started to autofill it with credit cards info:
Maybe someone is aware of what can cause such behavior?
I was sure that credit cards autofill is only available when correct name or autocomplete attributes are provided (like described here).
Additional details:
Before the library update input had no issue with autocomplete and was rendered like this:
<div class="search-input-container">
<input type="text" name="search" placeholder="Search for a customer" data-test-id="search__search-input__input" value="">
</div>
Also, when I'm deploying exactly the same version to a different environment with a different domain (which I wasn't using for a while) - I don't see an autofill issue.
According to this thread Chrome uses crowdsourcing (when many people entered the first name into the field - Chrome will classify it as a first name) to identify how to autocomplete the field.
However, if your input has the correct name and/or autocomplete attribute - it will work accordingly to that attributes.
After applying this fix and testing I can say, that it was probably the only way to fix the issue.

HTML Form / Input Autocomplete off

Autocomplete has been causing me trouble for quite some time. It overlays buttons and search results which causes users to click it instead of a link on the webpage.
I have been searching the internet for solutions to this for literally years. None of them are both practical and work consistently. I have tried all the alternatives to "off" listed throughout the relevant Google searches.
Below I have uploaded a GIF. The GIF shows me triggering autocomplete on an input which has autocomplete set to off.
I then remove the name attribute of a separate input within the form and suddenly autocomplete switches off.
I also demonstrate that having the keyword "Company" in the placeholder seems to override autocomplete=off. However, this does not seem to override autocomplete=off in all situations.
In the below example I used a datepicker, but I can also reproduced the problem with simple text inputs.
Is there a reason behind this strange behavior?
One solution is to use type="search", however, this may not be the desired approach for all developers.
Thanks in advance.
Have you tried this ?
<input name="unm" id="unm" type="text" autocomplete="false" readonly onfocus="this.removeAttribute('readonly');" />
Try using a form method.
<form method="post" action="">
<div>
<label for="cc">Please work:</label>
<input type="text" id="cc" name="cc" placeholder="Enter a company here" autocomplete="off">
</div>

How to restrict autofill for specific input tag?

I have an input tag which acts as a search box. But before that I have two input tags through which the credentials is given which gets saved in chrome browser. Now when the search box gets rendered it gets rendered with the autofill value of the username which was saved in the browser previously. My requirement is the autofill for the search input tag should not take place. I had used the following attributes for the search input tag but still it is not getting resolved.
<input type="text" spellcheck="false" autocomplete="off" name="my_custom_name">
Can anyone please provide me with a solution?
The latest way to do this is,Just simply use type search
<input type="search" />
autocomplete="off" toggles the application auto complete. Chrome browser has "Auto-fill" feature, where users can enable/disable. Hope you are not talking about this.

Autofilling form does not work on all browsers

I am trying to create an autofilling form for shippment details such as name, surname, street, postal code and so on. I want the form the autofil depending on the chosen "profile" - a data which was already filled in previously to avoid re-entering data if user uses the website many times.
When filling in the form clicking on submit and afterwards going back to the order page, the autofill is not possible.
tried:
https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill
https://www.w3.org/TR/html52/sec-forms.html
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
Raw code, without any changes:
<form class="f-form f-form--basket checkout">
<div class="f-form__col">
<div class="f-field f-field--text">
<label class="f-field__label" >
First name
</label>
<input type="text" class="f-field__control" name="firstName" placeholder="First name*" required>
</div>
</div>
<div class="f-form__col">
<div class="f-field f-field--text">
<label class="f-field__label">
Last name
</label>
<input type="text" class="f-field__control" name="lastName" placeholder="Last name*" required>
</div>
</div>
<button class="c-btn">
Pay!
</button>
</form>
You said your goal was to "autofill" the empty form with "data which was already filled in previously". That's two separate ideas that seem to be getting crossed here:
The documentation pages you link to reference a browser feature called "Autofill", which is the idea that an individual user in their own workstation's browser can fill in information about themselves (demographic information like name and email, and shipping address information), and then the browser can help them fill in forms properly.
This sort of function would work well for you, if the fields you're trying to fill in are standard demographics fields. But in order for the users to take advantage of it, it's up to to the user to update their browser's preferences to set their own "Autofill profile" (you can't do that as the web developer from HTML/JS.
The second part of what you said referenced data "they already filled in"; presumably you mean information they filled in on your site, the first time through? In order to get that idea to work, you would need to save the information the user entered, somehow. You could either save the data client-side in a cookie or other HTML5 local storage option, and use Javascript to re-fill in those values when the user visits the page again, or if the user has an account with you and is logged in, you can save that data on the back-end and generate the HTML with the default values already filled-in, or build some other API endpoint to fetch their default values via Javascript/AJAX from the front-end.