[ 
https://issues.apache.org/jira/browse/WICKET-7140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17912822#comment-17912822
 ] 

ASF GitHub Bot commented on WICKET-7140:
----------------------------------------

theigl commented on code in PR #1076:
URL: https://github.com/apache/wicket/pull/1076#discussion_r1914609818


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1273,9 +1273,11 @@ protected void 
addDefaultSubmitButtonHandler(IHeaderResponse headerResponse)
                String submitId = component.getMarkupId();
 
                AppendingStringBuffer script = new AppendingStringBuffer();
-               script.append("var b = 
document.getElementById('").append(submitId).append("');");
-               script.append("if (window.getComputedStyle(b).visibility === 
'hidden') return;");
-               script.append("if (event.which == 13) {");
+               script.append("if (event.which != 13) return true;");
+               // text area will submit on CTRL+Enter
+               script.append("if (event.target.tagName.toLowerCase() === 
'textarea' && !event.ctrlKey) return true;");

Review Comment:
   I don't think this is enough. I'm pretty sure we should to the same for 
`contenteditable` elements used by most WYSIWYG editors. How was form submit 
prevented for these elements before you submitted your original PR?



##########
wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/FormHierarchyDefaultButtonTestPage.java:
##########
@@ -33,6 +33,8 @@ public class FormHierarchyDefaultButtonTestPage extends 
WebPage {
     public final Button childSubmit;
     public final TextField<?> parentInput;
     public final TextField<?> childInput;
+       public final TextArea<?> parentTextarea;
+       public final TextArea<?> childTextarea;

Review Comment:
   Please fix the indentation here and also in the HTML files.





> Form submit triggered by pressing return in textareas
> -----------------------------------------------------
>
>                 Key: WICKET-7140
>                 URL: https://issues.apache.org/jira/browse/WICKET-7140
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-core
>    Affects Versions: 10.3.0
>            Reporter: Thomas Heigl
>            Priority: Major
>         Attachments: wicket-bug.zip
>
>
> Since upgrading to Wicket 10.3.0, pressing return in a textarea submits the 
> form when a `form.setDefaultButton()` is set. Downgrading to 10.2.0 fixes the 
> problem.
> Minimal reproducer:
> {code:java}
> public class HomePage extends WebPage {
>     public HomePage(final PageParameters pp) {
>        super(pp);
>        final Form<?> form = new Form<>("form");
>        form.add(new TextArea<>("textArea", new Model<>()));
>        final AjaxSubmitLink link = new AjaxSubmitLink("submit") {
>           @Override
>           protected void onSubmit(AjaxRequestTarget target) {
>              target.appendJavaScript("alert('Submitted');");
>           }
>        };
>        form.add(link);
>        form.setDefaultButton(link);
>        add(form);
>     }
> } {code}
> Click into the textarea and press return/enter.
> See also the attached quickstart.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to