Remove data from JQuery dialog box when I close it

后端 未结 5 1360
醉话见心
醉话见心 2021-02-06 00:31

I have JQuery dialog box for inserting new row in table. And everything works good. Few days ago when I inserted FlexiGrid for Table started a problem for me. When I insert new

相关标签:
5条回答
  • 2021-02-06 00:58

    Would it work if you add this line to the function of Save or Cancel?

     $( "#newDialog-form" ).html("");
    

    or more straight method (thx @mplungjan):

     $( "#newDialog-form" ).empty();
    

    It makes that all the content inside the dialog disappear, it's the best way so that last data does not appear.

    0 讨论(0)
  • 2021-02-06 01:00

    Check Dialog Close event. You will need to store the state of dialogue, state will include (title, text etc), if you are modifying it.

    Update

    After reading the comment, what I got, giving answer according to it. Please correct me if I'm wrong.

    Before you open the dailog form, store the html to local variable and then before closing it set the html back to the dialogue.

    var originalContent;
    $("#newDialog-form").dialog({
       //Your Code, append following code
       open : function(event, ui) { 
          originalContent = $("#newDialog-form").html();
       },
       close : function(event, ui) {
          $("#newDialog-form").html(originalContent);
       }
    });
    

    Hope this helps you.

    0 讨论(0)
  • 2021-02-06 01:05

    Why not create the HTML in dialog every time you open it and then do this:

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

    ..after you're done inserting the new record, usually after

    $('#yourForm').submit();
    

    Cheers!

    0 讨论(0)
  • 2021-02-06 01:10

    You can make use of the close event of jQuery dialogs.

    More information on jQuery UI.

    e.g.

    $( "#newDialog-form" ).dialog({
        ...
        close : function() {
            //functionality to clear data here
        }
    });
    
    0 讨论(0)
  • 2021-02-06 01:13

    you can clean all html content in DIV by setting the html property to nothing.

    $("#ElementId").html("");
    
    0 讨论(0)
提交回复
热议问题