Support the autocomplete attribute being set on the original <select> - #5839
Merged
Merged
Conversation
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.
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.
maxwellfet928
pushed a commit
to maxwellfet928/select2
that referenced
this pull request
Jun 8, 2026
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request includes a
The following changes were made
autocompleteattribute, when set, is now copied to the search boxes within the dropdown and selectionautocompleteoption can now be set without using the attributeIf this is related to an existing ticket, include a link to it as well.
Fixes #5628
Closes #5670