ruby-on-rails - 基于点击事件远程提交简单表单
问题描述
我正在尝试创建一个待办事项应用程序,其中复选框是使用简单表单创建的,并且需要在单击复选框时远程提交。我正在使用 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>
这会导致页面刷新,而不是远程提交表单。我发现的所有示例都在使用提交按钮。如何根据复选框单击触发远程执行?
解决方案
推荐阅读
- excel - 用于插入列和公式的 VBA 代码
- ubuntu - 可以以 root 身份而不是 ubuntu 用户身份 SSH 到 EC2 ubuntu 服务器
- azure - 无法从 Azure 容器注册表中拉取映像 - 拉取被拒绝
- python - 在 Python 应用程序中调用自定义 C 子例程
- python-2.7 - 我可以在 Mininet 仿真期间动态修改链接特性吗?
- python - python中的多行输入
- javascript - HTML 表单计算 - JS 还是 PHP?(多个变量)
- mongodb - MongoDB - 查找匹配一个字段但不匹配第二个字段的帐户
- python - 在 df.loc 过滤条件中填充缺失数据?
- node.js - 我有这个代码,它返回这个错误