Pregunta

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">
¿Fue útil?

Solución 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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top