문제

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