Rails 3
Currently facing an issue with 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 %>
Implemented a javascript function to handle the selection of radio buttons upon clicking the li element within the form.
<script type="text/javascript">
$('li').click(function() {
$(this).find('input[type=radio]').attr('checked', true);
$('#submit_category').click();
});
</script>
Encountering an issue specifically in the test environment where the radio button is not selected despite the form being submitted, resulting in a validation error.
Conducting tests using Cucumber + Selenium + Capybara. Excerpt from the testing script:
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