1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Trigger change events when clearing fields, closes #1072

This commit is contained in:
Jonas Nicklas 2013-11-10 14:10:56 +01:00
parent 8cd23d6351
commit c9ba16cd08
2 changed files with 15 additions and 3 deletions

View file

@ -37,9 +37,13 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
path_names = value.to_s.empty? ? [] : value
native.send_keys(*path_names)
elsif tag_name == 'textarea' or tag_name == 'input'
#script can change a readonly element which user input cannot, so dont execute if readonly
driver.browser.execute_script "arguments[0].value = ''", native unless self[:readonly]
native.send_keys(value.to_s)
if value.to_s.empty?
native.clear
else
#script can change a readonly element which user input cannot, so dont execute if readonly
driver.browser.execute_script "arguments[0].value = ''", native unless self[:readonly]
native.send_keys(value.to_s)
end
elsif native.attribute('isContentEditable')
#ensure we are focused on the element
script = <<-JS

View file

@ -129,6 +129,14 @@ Capybara::SpecHelper.spec "#fill_in" do
@session.find(:css, 'body').click
@session.find(:css, '.change_event_triggered', :match => :one).should have_text 'some value'
end
it 'should trigger change when clearing field' do
@session.visit('/with_js')
@session.fill_in('with_change_event', :with => '')
# click outside the field to trigger the change event
@session.find(:css, 'body').click
@session.should have_selector(:css, '.change_event_triggered', :match => :one)
end
end
context "with ignore_hidden_fields" do