【发布时间】:2020-02-12 00:08:06
【问题描述】:
我正在尝试创建一个待办事项应用程序,其中复选框是使用简单表单创建的,并且需要在单击复选框时远程提交。我正在使用 onchange() 函数,但表单没有被远程提交。它通过整页刷新提交。
当包含提交按钮时,它会远程提交表单并且一切正常。但我无法在没有提交按钮的情况下让它工作,而只能使用复选框。
_goal.html.erb
<li id='<%= "Goal_li_#{goal.id}" %>'>
<div class="collapsible-header" tabindex="0">
<label>
<%= simple_form_for(goal, url:goal_path(goal),remote: true,authenticity_token: true) do |f| %>
<%= f.check_box :is_complete,onchange: 'this.form.submit();', disabled:goal_disabled_class(goal), class: "check_box_check" %>
<span class=<%= "line-through-goal" if goal.is_complete==1 %>>
<%= goal.title %>-<%= goal.id %>-<%= goal.status %>
</span>
<%= "<span class='new badge blue right'> #{goal.sub_goals.where(is_complete: 0).count} </span>".html_safe if goal.sub_goals.where(is_complete: 0).count > 0 %>
<% end %>
</label>
</div>
</li>
这会导致页面刷新,而不是远程提交表单。我发现的所有示例都在使用提交按钮。如何根据复选框点击触发远程执行?
【问题讨论】:
标签: ruby-on-rails ajax simple-form