Question

I know this is a common problem. I've been looking at the various solutions proposed on this site and elsewhere but cannot hit upon something that works in my situation.

Here is my script:

$(function () {

    $('a.editPersonLink').live("click", function (event) {
        loadDialog(this, event, '#personList');
        $.validator.unobtrusive.parse('#editPersonContainer');
    });

    $(".deleteButton").live("click", function(e) {
        e.preventDefault();
        var $btn = $(this);
        var $msg = $(this).attr("title");

        confirmDelete($msg, 
            function() {
                deleteRow($btn, $target);
            });
    });

});

function loadDialog(tag, event, target) {
    event.preventDefault();
    var $loading = $('<img src="../../Content/images/ajaxLoading.gif" alt="loading" class="ui-loading-icon">');
    var $url = $(tag).attr('href');
    var $title = $(tag).attr('title');
    var $dialog = $('<div></div>');
    $dialog.empty();
    $dialog
        .append($loading)
        .load($url)
        .dialog({
            autoOpen: false
            ,title: $title
            ,width: 800
            ,modal: true
            ,minHeight: 200
            ,show: 'slide'
            ,hide: 'clip'
        });

    $dialog.dialog( "option", "buttons", {
        "Save": function () {
            var dlg = $(this);
            $.ajax({
                url: $url,
                type: 'POST',
                data: $("#formData").serialize(),
                success: function (response) {
                    $(target).html(response);
                    dlg.dialog('close');
                    dlg.empty();
                    $("#ajaxResult").hide().html('Record saved').fadeIn(300, function () {
                        var e = this;
                        setTimeout(function () { $(e).fadeOut(400); }, 2500);
                    });
                },
                error: function (xhr) {
                    if (xhr.status == 400) 
                        dlg.html(xhr.responseText, xhr.status);     /* display validation errors in edit dialog */
                    else 
                        displayError(xhr.responseText, xhr.status); /* display other errors in separate dialog */

                }
            });
        },
        "Cancel": function() { 
            $(this).dialog("close");
            $(this).empty();
        }
    });

    $dialog.dialog('open');
};

Right up near the top I am trying to cause the form to recognise the validation from the partial view on the dialog via the statement:

$.validator.unobtrusive.parse('#editPersonContainer');

editPersonContainer is the name of the div containing the data in the partial view loaded into the dialog.

The bottom line is that the validation is not recognised. Am I making the call to validator.unobtrusive.parse in the wrong place, or am I missing something else here?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top