甜蜜警报-无法向简单表单提交添加成功甜蜜警报

时间:2018-09-24 20:36:09

标签: javascript html ruby-on-rails sweetalert

**

function bindSweetAlertButtonDemo() {
  const swalButton = document.getElementById('sweet-alert-demo');
  if (swalButton) { // protect other pages
    swalButton.addEventListener('click', () => {
      swal({
        title: "Nice",
        text: "You've added a task. Click on it for more details",
        icon: "success"

      });

 event.preventDefault()


    });
  }
}
<div>
  <%= simple_form_for [ @task] do |f| %>
   <%= f.input :name %>
   <%= f.input :description %>
   <%= f.submit :submit, class: "btn btn-danger" ,id: "sweet-alert-demo" %>
  <% end %>

</div>

我试图用提交按钮创建一个表单,以将任务添加到索引页面。在提交时,我想要成功的甜蜜警报。但是,警报首先在毫秒后消失,但已通过preventdefault()解决了。但是现在提交实际上不再起作用了。有任何想法吗? (我已经正确导入了内容,只是没有将其添加到代码段中)

1 个答案:

答案 0 :(得分:0)

您需要定义//update columns and data without destroying the table $("#example-table").tabulator("setColumns", res["column"]); $("#example-table").tabulator("setData", res["data"]); 。如果用户单击event,则可以使用swal的{​​{1}}提交表单。

.then

演示:

Ok
swalButton.addEventListener('click', (event) => {
  swal({
    title: "Nice",
    text: "You've added a task. Click on it for more details",
    icon: "success"

  });
 event.preventDefault()
});