Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ If select2 field has [tags](http://ivaynberg.github.io/select2/#tags) option you
select2_tag('value', from: 'Label of input')
```

To deselect tag just do the following:

```ruby
select2_deselect_tag('value', from: 'Label of input')
```

## Contributing

1. Fork it
Expand Down
19 changes: 15 additions & 4 deletions gem/lib/capybara/selectors/tag_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ module Capybara
module Selectors
module TagSelector
def select2_tag(value, options = {})
find_select2_input(options).set(value)
find('.select2-drop li', text: value).click
end

def select2_deselect_tag(value, options = {})
find_select2_input(options).parent
.find('.select2-choices div', text: value)
.find(:xpath, 'following-sibling::a').click
end

private

def find_select2_input(options)
if options[:from]
find(:fillable_field, options[:from]).set(value)
find(:fillable_field, options[:from])
else
find('input.select2-input').set(value)
find('input.select2-input')
end

find('.select2-drop li', text: value).click
end
end
end
Expand Down