capybara_select2 icon indicating copy to clipboard operation
capybara_select2 copied to clipboard

Select2 with tag is using a textarea for the search input rather than an input

Open reggieb opened this issue 3 years ago • 2 comments

I'm using a select2 element with the tag option. When I use select2 'something', from: 'Something', tag: true I get the error:

Capybara::ElementNotFound:
       Unable to find css ".select2-container--open input.select2-search__field" within #<Capybara::Node::Element tag="body" path="/HTML/BODY[1]">

When I look at the code on the page, the .select2-search__field element is a textarea rather than an input. I think that's reflected in the select2 code here

I think additional search input selectors are needed. If I add this before select2 call:

CapybaraSelect2::Selectors::SearchInputSelectors = {'4' => ".select2-container--open textarea.select2-search__field" }

The test runs without error.

reggieb avatar Sep 23 '21 13:09 reggieb

I believe this change to CapybaraSelect2::Selectors::SearchInputSelectors will fix the problem:

    SearchInputSelectors = {
      '2' => ".select2-dropdown-open input.select2-focused",
      '3' => ".select2-drop-active input.select2-input," +          # single
             ".select2-dropdown-open input.select2-input",          # multi
      '4' => ".select2-container--open input.select2-search__field," +
             ".select2-container--open textarea.select2-search__field"
    }.freeze

reggieb avatar Sep 23 '21 15:09 reggieb

With what version of select2 plugin do you see this error, @reggieb?

Hirurg103 avatar Apr 04 '23 17:04 Hirurg103