Skip to content

Conversation

kevin-brown
Copy link
Member

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made

  • The autocomplete attribute, when set, is now copied to the search boxes within the dropdown and selection
  • The autocomplete option can now be set without using the attribute
  • Added tests for other options set via attributes

If this is related to an existing ticket, include a link to it as well.

Fixes #5628
Closes #5670

This adds a basic test to make sure that the `autocomplete` attribute
on the search box is set based on the value of the `autocomplete`
option that is passed in to Select2. This alows people to set the
`autocomplete` attribute on their `<select>`, which is valid
according to the spec, and have it copy over to the search box of
their Select2 instance.
This adds some missing tests for the disabled and multiple attributes
and how they can be used to set the corresponding options within
Select2. This also adds tests for the new autocomplete option that
ensures it is properly synchronized based on the attribute being
set.
This will now copy the `autocomplete` attribute (based on the current
state of the `autocomplete` DOM property) from the `<select>` to
any search boxes that are used by Select2. This is necessary to
both handle cases where people do not want the autocomplete
disabled, as well as handling cases where people are looking to set
a custom autocomplete which will assist users when searching.

This still maintains backwards compatibility with the `autocomplete`
option being set to `off` by default. It also allows the
`autocomplete` option to be set through the standard Select2 options
to override the `autocomplete` attribute if it is present.

This does not follow the precedent set by the `disabled` and `multiple`
options where the value is synchronized back to the original
`<select>` when it is overridden by the options. This is because it
would break backwards compatibility because the default state of
the `autocomplete` property is a blank string ('') instead of `off`
which is what Select2 uses.
Not all browsers, including older version of PhantomJS, support
the `autocomplete` attribute when it is set on a `<select>` element.
@kevin-brown kevin-brown merged commit e41cb2e into develop Apr 25, 2020
@kevin-brown kevin-brown deleted the GH-5628 branch April 25, 2020 02:22
@kevin-brown kevin-brown added this to the 4.1.0 milestone Apr 25, 2020
anttikuuskoski pushed a commit to anttikuuskoski/select2 that referenced this pull request Mar 29, 2022
…select2#5839)

* Add test to ensure search autocomplete attribute is set

This adds a basic test to make sure that the `autocomplete` attribute
on the search box is set based on the value of the `autocomplete`
option that is passed in to Select2. This alows people to set the
`autocomplete` attribute on their `<select>`, which is valid
according to the spec, and have it copy over to the search box of
their Select2 instance.

* Add tests for options set by HTML atttributes

This adds some missing tests for the disabled and multiple attributes
and how they can be used to set the corresponding options within
Select2. This also adds tests for the new autocomplete option that
ensures it is properly synchronized based on the attribute being
set.

* Add support for the autocomplete attribute

This will now copy the `autocomplete` attribute (based on the current
state of the `autocomplete` DOM property) from the `<select>` to
any search boxes that are used by Select2. This is necessary to
both handle cases where people do not want the autocomplete
disabled, as well as handling cases where people are looking to set
a custom autocomplete which will assist users when searching.

This still maintains backwards compatibility with the `autocomplete`
option being set to `off` by default. It also allows the
`autocomplete` option to be set through the standard Select2 options
to override the `autocomplete` attribute if it is present.

This does not follow the precedent set by the `disabled` and `multiple`
options where the value is synchronized back to the original
`<select>` when it is overridden by the options. This is because it
would break backwards compatibility because the default state of
the `autocomplete` property is a blank string ('') instead of `off`
which is what Select2 uses.

* Skip autocomplete attr test when not supported

Not all browsers, including older version of PhantomJS, support
the `autocomplete` attribute when it is set on a `<select>` element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to set a custom "autocomplete" html attribute
1 participant