Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reopen modal dialog in jquery after closing it?

I have an Asp.Net MVC application, where in 1 View, I have a list with every record showing Edit icon. Clicking the edit icon opens a modal dialog popup to update the record .

I face problem in reopening the dialog or clicking other edit icon for popup after closing the dialog . Following is my jquery code to open the dialog :

var singltym;

$(function () {

    $('#addSingleTimeDialog').dialog({
            cache: false,
            autoOpen: false,
            width: 450,
            height: 450,
            closeOnEscape: true,
            resizable: true,
            modal: true});

    $('#singletymlink').on('click', function () {
            singltym = $(this);
            var dialogDiv = $('#addSingleTimeDialog');
            var viewUrl = singltym.attr('href');
            $.ajax({
                cache: false,
                url: viewUrl,
                dataType: 'html',
                success: function (data) {
                    dialogDiv.html(data);
                    dialogDiv.dialog('open');
                }
            });
            return false;
        });
});
like image 768
Shalin Jirawla Avatar asked Dec 21 '22 05:12

Shalin Jirawla


2 Answers

    var singltym;

    $(function () {

        $('#addSingleTimeDialog').dialog({
                cache: false,
                autoOpen: false,
                width: 450,
                height: 450,
                closeOnEscape: true,
                resizable: true,
                modal: true});

        $('#singletymlink').on('click', function () {
                singltym = $(this);
                var dialogDiv = $('#addSingleTimeDialog');
                var viewUrl = singltym.attr('href');
                $.ajax({
                    cache: false,
                    url: viewUrl,
                    dataType: 'html',
                    success: function (data) {
                        dialogDiv.html(data);
                       dialogDiv.dialog('open');

//I work in this method

                  $( this ).dialog( "close" );

                }
            });
        });
});

Or

$.ajax({
                    cache: false,
                    url: viewUrl,
                    dataType: 'html',
                    success: function (data) {
                        dialogDiv.html(data);
                       $("#dialogDiv").dialog("open");

                  $( this ).dialog( "close" );

                }

If $( this ).dialog( "close" ); not working because not try this specific sentence??

$('#addSingleTimeDialog').dialog("close");
like image 121
Mirko Cianfarani Avatar answered Dec 22 '22 18:12

Mirko Cianfarani


The above issue can be solved by including the below scripts in parent view from where the dialog popup is clicked & initiated :

<script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.unobtrusive.min.js"></script>

As well as insert the below scripts in child view which is the UI for modal dialog popup :

<script type="text/javascript" src="../../Scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.unobtrusive.min.js"></script>

By scripting in such way, the jquery script conflict is avoided & reopening of dialog can be swiftly done.

like image 22
Shalin Jirawla Avatar answered Dec 22 '22 19:12

Shalin Jirawla