implementing a confirm dialog on an sj:submit

637 views
Skip to first unread message

ava

unread,
Jul 18, 2012, 9:10:17 AM7/18/12
to struts2...@googlegroups.com
Hello again guys, i'm trying to display a confirmation dialog once i submit a form. Everything seems to be working, except the most important thing: the dialog opens correctly, but the action of the form gets executed anyway every time. Here's my code

<s:form id="form" action="action">
<sj:dialog 
id="confirmDia" 
buttons="{ 
'OK':function(){okButton();},
'Cancel':function() {cancelButton();} 
}"
autoOpen="false" 
modal="true" 
resizable="false"
>
Some Dialog text
</sj:dialog>
<sj:submit 
targets="usersContent"
type="image" 
value=""
cssClass="tableButton"
src="/image.png"
title="Some Title"
indicator="indicator"
openDialog="confirmDia"
></sj:submit>
<script type="text/javascript">
function okButton(){
$("#form%{#it.count}").submit();
};
function cancelButton(){
$("#confirmDia").dialog("close");
};
</script>
</s:form>

jchin

unread,
Jul 18, 2012, 11:54:56 AM7/18/12
to struts2...@googlegroups.com
if you use .submit(), the form will submit normally, i.e. non-ajax
$("#form%{#it.count}").submit();

you need to use topic instead.

In you sj:submit tag, add a listen topics

for e.g. listenTopics="submitFormUsingAjaxTopic"

In your okButton function, publish the topic

function okButton(){
 $.publish("submitFormUsingAjaxTopic");
};

ava

unread,
Jul 20, 2012, 3:54:54 AM7/20/12
to struts2...@googlegroups.com
The problem persists.. i modified the code this way;

<s:form id="form" action="action">
<sj:dialog 
id="confirmDia" 
buttons="{ 
'OK':function(){okButton();},
'Cancel':function() {cancelButton();} 
}"
autoOpen="false" 
modal="true" 
resizable="false"
>
Some Dialog text
</sj:dialog>
<sj:submit 
targets="usersContent"
type="image" 
value=""
src="/images/image.png"
title="SomeTitle"
indicator="indicator"
listenTopics="submitFormUsingAjaxTopic"
openDialog="confirmDia"
>
</sj:submit>
<script type="text/javascript">
function okButton(){
$.publish("submitFormUsingAjaxTopic");
};
function cancelButton(){
$("#confirmDia").dialog("close");
};
</script>
</s:form>

The problem is still the same: the dialog opens but the action gets performed anyway, then it closes after 1 second.
Reply all
Reply to author
Forward
0 new messages