javascriptjqueryjquery-dialog

buttons not working properly in jq dialog content (two ways of closing jquery dialog with bootstrap table)?


I'm working with bootstrap table inside of jquery dialog and having problems with closing dialog and freeing memory. Let me show on demo code:

Method 1: jsFIDDLE Here is the code with two buttons inside dialog content which I use to save or cancel. They are coded with $.click() (not by dialog). To see the problem fallow 4 steps:

  1. Click first checkbox and accept date
  2. Do the same for the second checkbox
  3. Uncheck both (date field is empty in both rows)
  4. Check again one checkbox and accept date

You will notice now that the date was added into both fields of each row even if didn't click the second one. When I play more like this I can even uncheck both checkboxes with one click.

Method 2: jsFIDDLE The same idea, but I use buttons defined in jquery dialog and if you do the same steps from above, you won't notice the problem - it works just fine.

Question: I need to use the first method for my own purpose, but what to do to fix this memory problem?


Solution

  • You have a scope problem in your code; Please try this updated Fidle

      var currentRow = null;
    
     $("#pickdate").datepicker({dateFormat: "dd-mm-yy"}).datepicker("setDate",new Date());
    $('#table').on('check.bs.table', function (e, row, $el) {
    
    currentRow = row;
    
         $("#dialog").dialog({
                    dialogClass: "no-close tt",
                    modal: true,
                    title: "Data zamknięcia",
                    width:189,
            });
    
    
    });
    

    See fidle for full code