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

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

theigl commented on PR #1076:
URL: https://github.com/apache/wicket/pull/1076#issuecomment-2597676579

   Let's take a step back and think about this once again.
   
   1. The original behavior prior to your PR #971 was that forms could not be 
submitted via ENTER from multiline fields. This is what I would consider 
"default" browser behavior.
   2. Your first PR changed that and forms can now be submitted via ENTER from 
multiline fields. This is problematic.
   3. This PR now attempts to solve this by making the submit handling 
configurable and restoring the original behavior.
   
   For me, this PR is doing too many things. I think we should simply restore 
the original behavior. Submitting a form from multiline fields is something 
that is rarely needed, and if it is needed it can be easily added to a textarea 
as a behavior. We are using this in our project:
   
   ```java
   public final class KeyboardSubmitBehavior extends WiQueryEventBehavior {
   
        private static final String SUBMIT_SELECTOR = 
"input[type='submit'],button[type='submit'],[name=':submit']";
   
        public KeyboardSubmitBehavior(final KeyboardEvent keyboardEvent) {
                super(new Event(KeyboardEvent.KEYDOWN) {
                        @Override
                        public JsScope callback() {
                                return JsScopeEvent.quickScope("if 
((event.which == 10 || event.which == 13) && event.ctrlKey) { " +
                                                
"$(this).closest('form').find(\"" + SUBMIT_SELECTOR + "\").trigger('click'); 
return false; " +
                                                "}");
                        }
                });
        }
   }
   ```
   
   Then we don't need a separate `form.js` file and most of the complexity goes 
away.
   
   What do you think @solomax and @martin-g?




> 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