【问题标题】:Form is not getting submitted with unobtrusive javascript in rails表单未在 Rails 中使用不显眼的 javascript 提交
【发布时间】:2014-04-21 19:50:05
【问题描述】:
<%= form_for(current_user, url: update_my_profile_path, :method => :post, remote: true ) do |f| %>

   First Name: <%= f.text_field :firstname, value: current_user.firstname %>
   Last Name: <%= f.text_field :lastname, value: current_user.lastname %>
   Phone No. <%= f.text_field :phone, value: current_user.phone  %>

<%= f.submit  'update details', remote: true  %>

在我的 Javascript 文件中验证:

 $("#personal_profile_update form").validate({

        rules: {
                firstname: { //validation rule },

                lastname: { //validation rule }

                }, // End of the rules

      messages: {    } // End of the messges section
});

这里的验证效果很好。但是当我尝试在表单和 f.submit 中使用 remote: true 选项提交表单时,它不会被提交。 一旦我删除了这个 jquery.validate,这个表单就会使用 remote: true 选项提交。

有什么方法可以提交这个表单,远程:true 选项被应用验证规则激活???

【问题讨论】:

    标签: ruby-on-rails forms ujs


    【解决方案1】:

    这是讨论here Judge gem 用于客户端验证。 RailsCasts 有一整集关于使用客户端验证 gem。

    【讨论】:

      猜你喜欢
      • 2011-09-22
      • 1970-01-01
      • 2011-06-05
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 2010-12-14
      相关资源
      最近更新 更多