Rails 3
I have a list inside a form:
<%= form_for @article do |f| %>
<ul>
<% @product.each do |p| %>
<li id="product_<%=p.id%>">
<div>
<%= f.radio_button(:p_id, p.id, class: 'hidden') %>
</div>
</li>
<% end %>
</ul>
<%= f.submit 'submit', :id=>"submit_category", :class=>'hide' %>
<% end %>
I added a javascript function so that when the user clicks on the li element, the radio button is selected and the form is submitted.
<script type="text/javascript">
$('li').click(function() {
$(this).find('input[type=radio]').attr('checked', true);
$('#submit_category').click();
});
</script>
This works perfectly in production, development, but the test environment fails: the form IS submitted, but the radio button is not selected, so I get a validation error.
My tests are done with Cucumber + Selenium + Capybara. Line of testing:
When /^I click on the "(.*?)" product$/ do |product_name|
@product = Product.find_by_name(product_name)
page.find('li', id: "product_#{@p.id}").click
end
猜在这里,但没有包装的代码$(函数(){..your代码})(domready中)回调的帮助?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.