سؤال

I have the following codes, saveBt, should not submit when user selects cancel on confirm however it seems it still submits cause I have onClickTopics, I need this onclicktopics to reload a struts jquery grid. Any workarounds?

$("#saveBt").click(function(event){
                event.preventDefault();
                if($('#Form').valid()){
                    if (confirm("Are you sure ?")) {
                        return true;
                    } else {
                        return false;
                    }
                }
            });

<sj:a id="saveBt" onClickTopics="reloadGrid" name="saveChannel" value="saveChannel">Save</sj:a>

UPDATE: Need onClicks to reload grid via :

<sj:a id="saveBt" onClickTopics="reloadGrid" name="save" value="save">Save</sj:a>
<sjg:grid id="gridTable"  reloadTopics="reloadGrid" resizable="true"
                     autowidth="true">
هل كانت مفيدة؟

المحلول 3

Ended up with:

    function validator() {
        if (confirm("Are you sure you want to save?")) {
            $("#Form").submit();
            $("#refresh_gridTable").click();
        }
    }

<sj:a id="saveBt" onclick="return validator();">Save</sj:a>

Struts jquery Grid creates a refresh button via setting : navigatorRefresh="true" just had to click it after submit.

نصائح أخرى

try this, delegate method.

$(document).on('click','#saveBt', function(event){
  event.preventDefault();
  if($('#Form').valid()){
    if (confirm("Are you sure ?")) {
      return true;
    } else {
      return false;
    }
  }
})

Reload the grid after the click event fire.That is inside the binding method. Then call the event.preventDefault after you reload the grid.

The point is not to bubble the event after the grid reload. If it's that what you mean.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top