表单验证插件不验证表单



我正在使用formValidation来验证ASP.NET MVC应用程序中Bootstrap表单。自从它被称为bootstrapValidator以来,我一直使用这个插件,从未遇到过困难。现在我正在尝试驯服 0.6.2 版本,但无法设置要验证的字段。

我在页面底部有以下脚本:

<script src="/Scripts/jquery-1.11.2.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.form.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/formValidation/formValidation.js"></script>

下面我放置了我的模态:

<div aria-hidden="true" aria-labelledby="modalBox_label" role="dialog" tabindex="-1" id="modalBox" class="modal fade"></div>

我有部分视图来填充我的模式与用户的操作。我想最重要的部分是形式:

@using (Html.BeginForm("SomeAction", "SomeController", new { area = "SomeArea", divModal = divModal, divTarget = divTarget }, FormMethod.Post, new
{
    id = modalForm,
    @role = "form",
    @class = "form",
    @data_divTarget = "#" + divTarget
}))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(m => m.Id)
    <div class="modal-body form-horizontal">
        <div class="form-group">
            @Html.LabelFor(m => m.Name, new { @class = "control-label col-sm-3" })
            <div class="col-sm-5">
                @Html.TextBoxFor(m => m.Name, new { @data_fv_notempty_message="You must enter name", @data_fv_notempty="True", @class="form-control", placeholder="Enter name" })
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <input type="submit" value="Submit form" class="btn btn-primary" />
    </div>
} 

加载分部视图时,生成的代码如下所示:

<div aria-hidden="false" aria-labelledby="modalBox_label" role="dialog" tabindex="-1" id="modalBox" class="modal fade in" style="display: block;">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button" id="modalBox_btnClose"><span aria-hidden="true">×</span><span class="sr-only">Закрыть</span></button>
            <h4 id="modalBox_label" class="modal-title">Some title</h4>
        </div>
        <form role="form" method="post" id="modalBox_form" data-divtarget="#divTarget" class="form fv-form fv-form-bootstrap" action="/SomeController/SomeAction" novalidate="novalidate">
            <button type="submit" class="fv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
            <input type="hidden" value="someToken" name="__RequestVerificationToken">
            <input type="hidden" value="0" name="Id" id="Id">
            <div class="modal-body form-horizontal">
                <div class="form-group">
                    <label for="Name" class="control-label col-sm-3">Name</label>
                    <div class="col-sm-5">
                        <input type="text" value="" placeholder="Enter name" name="Name" id="Name" data-fv-notempty-message="You must enter name" data-fv-notempty="True" class="form-control">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
                <input type="submit" class="btn btn-primary" value="Submit form">
            </div>
        </form>
    </div>
    <div style="display: none; width: 0px; height: 0px;">
        <script>
            $(document).ready(function () {
                validateModalForm('#modalBox_form');
            });
        </script>
    </div>
</div>
</div>

哦,我的表格下面的小脚本!它用于调用formValidation插件,代码在这里:

function validateModalForm(formId) {
    $(formId).formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        }
    }).on('success.form.fv', function (e) {
        alert('Keep calm and do submit');
    });
}

当我单击提交按钮时,它会返回警报消息,然后提交。我无法检测到问题。帮助!:(

好的,问题就在这里:data-fv-notempty="True"该值应以小写形式写入:data-fv-notempty="true"

相关内容

  • 没有找到相关文章

最新更新