私信  •  关注

Georgi Koemdzhiev

Georgi Koemdzhiev 最近创建的主题
Georgi Koemdzhiev 最近回复了
4 年前
回复了 Georgi Koemdzhiev 创建的主题 » 为什么我的JQuery自定义数据验证在提交时没有执行?

我设法通过移动 $.validator.addMethod $.validator.unobtrusive.adapters.add showSharingView 方法。成功了,我的自定义错误显示正确。但是,我不知道为什么:

<script type="text/javascript">

    var isEmailAdapterName = 'isEmail';
    // client-side email validation
    $.validator.addMethod(isEmailAdapterName, IsEmailValid);
    // register the 'isEmail' attribute with the 'unobtrusive' validation
    $.validator.unobtrusive.adapters.add(isEmailAdapterName,
        [],
        function(options) {
            // add a 'isEmail' rule to the options so that JQuery can find it when it's checking the rules collection
            options.rules[isEmailAdapterName] = {};
            // add a message for the 'isEmail' rule ('message' will have the 'ShareModel' attribute 'ErrorMessage' value)
            options.messages[isEmailAdapterName] = options.message;
        });

    function showSharingView(title, workbookId, id) {
        $('.share-button').prop('disabled', true); // Disable all share buttons to avoid opening multiple dialogs
        // reset the 'Emails' textarea 
        $('#Emails').val('');
        // set the dialog's control values
        $('#Title').val(title);
        $('#Id').val(id);
        $('#WorkbookId').val(workbookId);
        // set the dialog's title 
        $('#dialogDisplayTitle').html("Share Workbook - " + title);

        $('#shareFormModal').modal("show");
    }