【问题标题】:Validation on meteor form submit with jquery使用 jquery 验证流星表单提交
【发布时间】:2023-04-02 23:40:01
【问题描述】:

我正在尝试通过使用 jquery 和流星来控制电子邮件,当我写错邮件地址时会收到错误消息,但是当我写为 true 时,页面会刷新但不会将邮件保存在数据库中。

$('commentForm').validate({
    sendForm: false,
    valid: function() {  
        var ebulten=template.$('#cemail').val();
        var o={}
        o.ebulten=template.$('#cemail').val();
        Ebulten.insert(o);
        alert("it's done!");
        console.log("valid !");
    }
});

页脚布局.html

<template name="footerLayout">
    <div id="footer" class="footer">
        <div class="container">
<form class="cmxform" id="commentForm" action="" method="get">
  <div class="form-group"><span class="f-s-20 text-white">E-Bültene Kayıt     Ol</span></div>
  <div class="form-group"><input name="email" id="cemail"  type="email" class="form-control width-250 m-auto" placeholder="E-  Bültene Kayıt Ol" required></div>
   <div class="form-group"><button type="submit"  id="ebultenkaydet" class="btn btn-theme width-250">E-Bültene Kayıt Ol</button>                     
</div>
</form>
</div>
 </div>
</div>
</template>

【问题讨论】:

  • 是否安装了 jQuery.validate()?这不是 Meteor 的标准。您必须安装类似atmospherejs.com/cramhead/jquery-validate 的东西,一个常见的模式是完全避免表单提交,只需添加一个模板事件来直接处理您的提交按钮的点击,在您的情况下,'#ebultenkaydet click'

标签: jquery validation meteor


【解决方案1】:

您是否尝试将 event.preventDefault() 添加到您的模板提交事件?

【讨论】:

  • 我试过了,但结果相同。 Template.footerLayout.events({ '点击#ebultenkaydet': function(e,template){......
  • 啊,也许可以尝试将事件从点击更改为提交。这应该会让 event.preventDefault() 生效。
猜你喜欢
  • 2014-12-14
  • 2012-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-30
相关资源
最近更新 更多