我的代码在这里
<%= form_for @subscription, :html => {:id => "gift-card-payment-form"}, :as => :subscription_config, :url => activate_gift_card_path do |f| %>
<%= f.hidden_field :plan_type, :id => "account_type" %>
<div id="payement-form-fields-gift">
<div class="form-group">
<%= f.label :addr1, "BILLING ADDRESS"%>
<%= f.text_field :addr1, {:placeholder => "Enter Street Address", :class => "input_text ui-shadow-inset ui-corner-all", :required => "true"}%>
<span class="error-message-left">
<%= @subscription.andand.errors[:addr1].andand.first %>
</span>
</div>
<%= f.submit "SUBMIT & START READING", :class => "btn btn-gray top10", :id => "payment-submit", :disabled => "true" %>
<% end %>
$(document).ready(function () {
$("#gift-card-payment-form").validate({
rules: {
"subscription_config[addr1]": {
required: true
}
},
messages: {
"subscription_config[addr1]" : {
required: "This field is required"
}
}
// ,
// submitHandler: function(form) {
// $('#payment-submit').attr("disabled", false);
// $('#payment-submit').addClass('active');
// }
});
});
</script>
这项工作有时但是工作不正常请帮助我。
答案 0 :(得分:1)
您应该在输入中使用:required => true
,而不是:required => "true"
。经过更正后,您可以删除所有传递的选项,只需拨打$("#gift-card-payment-form").validate();
。