淘汰赛和jQuery验证

时间:2014-03-12 15:11:42

标签: javascript jquery asp.net knockout.js jquery-validate

我目前有以下模式,使用Knockousjs进行数据绑定,数据绑定工作正常,但是当我尝试设置jquery验证器时,有效总是返回true。

    <!-- edit modal -->
<div class="modal fade" id="editDataClassModal" tabindex="-3" role="dialog" aria-hidden="true" data-bind="with: selectedTag">
    <div class="modal-dialog">
        <form id="editDataClassForm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Edit Data Classification</h4>
                </div>
                <div class="modal-body">

                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-3 paddingTop3">
                                Classification:
                            </label>
                            <div class="col-md-9">
                                <input type="text" id="txtClassification" name="txtClassification" class="form-control" data-bind="value: copyname" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" id="btnCancelEdit" class="btn btn-primary btn-sm buttonsize" data-dismiss="modal">Cancel</button>
                    <input type="submit" value="submit" id="btnSubmit"/>
                    <button type="button" id="btnSaveEdit" class="btn btn-primary btn-sm buttonsize">Save</button>
                    <div class="marginTop10">
                        <span class="label-danger" id="lblErrorEdit" style="display: none;">An error occurred while saving this record.</span>
                    </div>
                </div>
            </div>
            <!-- /.modal-content -->
        </form>
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

和正在使用的验证器:

        var edidDataClassValidator = $("#editDataClassForm").validate({
        rules: {
            txtClassification: {
                required: true,
                minlength: 2
            }
        },
        messages: {
            txtClassification: {
                minlength: "Classification must consist of at least 2 characters"
            }
        },
        errorPlacement: function (label, element) {
            label.addClass('errorText');
            label.insertAfter(element);
        },
        wrapper: 'span'
    });

单击btnSaveEdit按钮时,运行以下命令:

    $(document).on("click", "#btnSaveEdit", function(e) {
        $("#editDataClassForm").removeAttr("novalidate");
        var form = $("#editDataClassForm");
        if (form.valid()) {
            var itemToEdit = ko.dataFor(this);
            alert('valid ' + itemToEdit);
        } else {
            alert('not valid');
        }
        e.preventDefault();
    });

如果我从模态中删除数据绑定验证器开始工作,那么我假设它是jquery验证器和淘汰赛的问题?

0 个答案:

没有答案