rails中的jQuery验证无法按预期工作

时间:2015-08-02 15:25:46

标签: jquery ruby-on-rails validation jquery-form-validator

我已经在这个问题上工作了一天并尝试了各种解决方案,但它们似乎都没有起作用。

<%= form_tag("/report", method: "post", id: 'report-form') do |f|%>

    <div class="form-group">
        <%= radio_button_tag :report_reason, 1 %>
        <%= label_tag :report_reason_l, 'Inappropriate Photo' %>
    </div>
    <div class="form-group">
        <%= radio_button_tag :report_reason, 2 %>
        <%= label_tag :report_reason_l, 'Seems Like Spam' %>
    </div>
    <div class="form-group">
        <%= radio_button_tag :report_reason, 3 %>
        <%= label_tag :report_reason_l, 'Underage User' %>
    </div>
    <div class="form-group">
        <%= radio_button_tag :report_reason, 0 %>
        <%= label_tag :report_reason_l, 'Other' %>
    </div>
    <div class="form-group">
        <%= text_area_tag 'report_description', nil, placeholder: 'Description...', :autofocus => true, rows: 3, class: 'form-control' %>
    </div>
    <div class="form-group">
        <%= submit_tag "Report", class: "btn btn-primary", id:'submit-report' %>
    </div>

<% end %>
<script>
$(function() {
    $('#report-form').validate({
        rules: {
            'report_description' : {
                required : true
            }
        },
        messages: {
            'report_description' : {
                required : "Please mention the reason for reporting this"
            }
        }
        submitHandler: function(form) {
            form.submit();
        }
    });
});
</script>

此处的验证是:如果用户不能将说明留空。

jsfiddle链接是PHP's documentation
我在哪里验证错误?

0 个答案:

没有答案