Choices
Choices copied to clipboard
Preserve autofocus attribute or add a shouldFocus option
Is your feature request related to a problem? Please describe.
Unless I am mistaken when an input field has an autofocus
attribute, Choices does not autofocus to this field. Probably because the autofocus remains on the hidden field
Describe the solution you'd like I see two options
- detect the
autofocus
attribute and forward it to the choices input - add a new option
shouldFocus
Describe alternatives you've considered
Currently, I have a workaround using a callback in callbackOnInit
callbackOnInit: function () {
this.input.focus()
}
This is a simpler version of what I am using since typically I can have multiple fields on my page with only one being autofocused. So there is a need for additional logic. This is where having this as an option or directly compatible with the autofocus attribute would be very nice
It would be nice feature. Thumbs up!
I had the same issue. The Code provided by @adrienpoly does no longer work. Here is my Solution:
new Choices(input, {
callbackOnInit: function() {
if(this.passedElement.element.autofocus) {
this.showDropdown();
this.input.focus();
}
}
});
Tested on Version 10.1.0