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

Prevent browser autocomplete suggestions on Choices elements #908

Merged
merged 2 commits into from
Dec 22, 2021

Conversation

bobmaerten
Copy link
Contributor

This is the problem:

Safari will display a contact autocomplete on every text input which name attribute contains "name" or does not have any name attribute.
Capture d’écran 2020-09-24 à 16 27 58

Steps to reproduce:

Use defaut Choices.js (9.0.1) with macOS Safari

This is my solution:

Adding a fine tuned nameattribute to the input should prevent that.

Plus, input type="search" seems more suited to the field intent (https://developer.mozilla.org/fr/docs/Web/HTML/Element/Input/search).

In the mean time, I'm using the same kind of solution explained in #598 (comment), mimic-ing the attribute addition in this PR as a JS callback on page loaded:

   const els = document.querySelectorAll('.choices__input--cloned');
    els.forEach((el, n) => {
      el.setAttribute("name", "search_terms")
      el.setAttribute("inputmode", "search")
    });

Types of changes

  • Chore (tooling change or documentation change)
  • Refactor (non-breaking change which maintains existing functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@bobmaerten
Copy link
Contributor Author

Holy cow, I wasn't prepared to all those failing tests! /o
Could someone guide me towards passing tests according to the changes I made (I'm a ruby guy)

@Defcon0
Copy link

Defcon0 commented Oct 8, 2020

Big thanks to you for fixing this!

@mtriff
Copy link
Member

mtriff commented Dec 21, 2021

This seems good. Those test failures likely weren't anything to do with your change. Can you rebase on the latest version of master? I expect it will run cleanly and we can merge this.

@bobmaerten
Copy link
Contributor Author

I can't easily rebase this patch as I made it from the GitHub editor. All I can do is close this PR and make another one after I cloned the repo on my account.

@mtriff
Copy link
Member

mtriff commented Dec 21, 2021

Sounds good, that works too!

Safari will display a contact autocomplete on every text input which `name` attribute contains "*name*" or does not have any `name` attribute.
Adding a fine tuned `name`attribute to the input should prevent that.

Plus, input type="search" seems more suited to the field intent (https://developer.mozilla.org/fr/docs/Web/HTML/Element/Input/search).
@bobmaerten
Copy link
Contributor Author

I did manage to set up a remote branch on my setup and rebase the commit onto master.

@mtriff
Copy link
Member

mtriff commented Dec 22, 2021

Great! Just the one failing test now (much better 😁). Can you update the test at src/scripts/templates.test.ts:507?

@mtriff mtriff added the bugfix Pull request that fixes an existing bug label Dec 22, 2021
@mtriff mtriff linked an issue Dec 22, 2021 that may be closed by this pull request
Copy link
Member

@mtriff mtriff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parfait, merci!

@mtriff mtriff merged commit 82b9422 into Choices-js:master Dec 22, 2021
@mtriff mtriff changed the title Enhance inputCloned text input with type and name Prevent browser autocomplete suggestions on Choices elements Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Pull request that fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Browser native autocomplete displays over choices dropdown
3 participants