Skip to content

Commit

Permalink
WICKET-6525 restored check for onsubmit on form
Browse files Browse the repository at this point in the history
which was lost in WICKET_6348
  • Loading branch information
Sven Meier committed Feb 4, 2018
1 parent 36b8402 commit abedb46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Expand Up @@ -207,9 +207,18 @@ protected CharSequence getTriggerJavaScript()
// find the root form - the one we are really going to submit
Form<?> root = getForm().getRootForm();

StringBuilder script = new StringBuilder();
if (shouldInvokeJavaScriptFormOnsubmit())
{
script.append(String.format("var ff=document.getElementById('%s');", getForm().getMarkupId()));
script.append("if (typeof ff.onsubmit === 'function' && ff.onsubmit() == false) return false;");
}

CharSequence url = urlForListener(new PageParameters());

return root.getJsForListenerUrl(url);
script.append(root.getJsForListenerUrl(url));
script.append("return false;");

return script;
}
else
{
Expand Down
Expand Up @@ -11,13 +11,13 @@ <h1>wicket.markup.html.form.SubmitLink</h1>

<p>
A SubmitLink is a special link that acts like a submit button.
It can be inside the form component or inside the form component.
It can be inside the form component or outside the form component.
</p>
<p>
<form wicket:id="form">
<form wicket:id="form" onsubmit="return confirm('Do you really want to submit?');">
<a wicket:id="internal">Internal SubmitLink</a>
</form>
<a wicket:id="external">External SubmitLink</a>
<a wicket:id="external">External SubmitLink with confirmation</a>
<span wicket:id="feedback">feedbackmessages will be put here</span>
</p>
<span wicket:id="explainPanel">panel contents come here</span>
Expand Down
Expand Up @@ -44,6 +44,12 @@ public SubmitLinkPage()

SubmitLink internal = new SubmitLink("internal")
{
@Override
protected boolean shouldInvokeJavaScriptFormOnsubmit()
{
return false;
}

@Override
public void onSubmit()
{
Expand Down

0 comments on commit abedb46

Please sign in to comment.