0

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

<%= 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 链接在这里
我在哪里验证错误?

4

0 回答 0