cool, i will try to get to it whenever i have the time. i have some ideas in my head on how to make it nice and clean.

-Igor


On 2/9/06, Gustavo Hexsel <[EMAIL PROTECTED]> wrote:
  Hi Igor,

  thanks a lot for the suggestions.  I've tried creating very simple specialized panels that behaved as the "submit buttons" and a "submit button group".

  I'm attaching the code for anyone curious or desperate enough.  I don't know enough of how to make proper wicket components, so this probably breaks a hundred wicket design rules - but it solves my problem.  Feel free to fix, modify, add, or reuse in any manner.  Things I know are bad:
- you can only have one form (damn JS)
- you cannot have a field with an id of "submittedButton" (ditto for JS)
- you can only have one SubmitButtonGroup
- get/setButtonId shouldn't be public, or some other model type should be used
- no docs, no tests (ARGH there goes test first down the drain :)

  To use it, just include a <span> element for each of the buttons, and one for the button group.  In the Java code, add something like this to the form:
        private void addButtons() {
                group = new SubmitButtonGroup("buttonGroup");
                final SubmitButton searchButton = new SubmitButton("searchButton", "Search", group);
                add(searchButton);
                add(new SubmitButton("browseButton", "Browse", group));

                group.setDefaultButton(searchButton);
                add(group);
        }

        protected void onSubmit() {
                if ("searchButton".equals(group.getButtonId())) {
                        search();
                } else if ("browseButton".equals( group.getButtonId())) {
                        browse();
                } else {
                        logger.error("Unexpected submit");
                }
        }

  []s Gus



---------- InĂ­cio da mensagem original -----------

      De: [EMAIL PROTECTED]
    Para: [email protected]
      Cc:
    Data: Wed, 8 Feb 2006 20:28:31 -0800
Assunto: Re: [Wicket-user] Default button when hitting Enter

> i believe this is actually how all browsers/html work. the first button in
> the form is always the default one. it sucks, you just have to learn to work
> around it.
>
> a while back i really needed this to work properly. so what i did was use
> _javascript_.
>
> add a hidden input to the form and initialize it with the name of the
> default button.
>
> then each button becomes type="button" instead of type="submit" and onclick
> you do something like this.form.tracker=this.name; this.form.submit
> ;"
>
> that way your hidden input always contains the name of the button clicked,
> or default one if form was submitted using enter.
>
> another thing to try is to set taborder on the form controls, maybe that way
> the button with lowest tab order becomes the default, but i havent tried it
> and dont know if its cross browser.
>
> i suppose we could design a _javascript_ system like above for wicket. if you
> are willing to put in the time to do it i would be willing to help.
>
> -Igor
>
>
> On 2/8/06, Gustavo Hexsel < [EMAIL PROTECTED]> wrote:
> >
> >   Hi all,
> >
> >   is there a way of setting which one is the default button when hitting
> > Enter on a form?  I've tried looking for Wicket or _javascript_ solutions, I
> > can't seem to find something that will post the correct button on the form -
> > it's always the first one in the markup.
> >
> >   The closest I've got was:
> > --------------------------------------
> >         function submitEnter(myfield,e) {
> >                 var keycode;
> >                 if (window.event) {
> >                         keycode = window.event.keyCode;
> >                 } else if (e) {
> >                         keycode = e.which;
> >                 } else {
> >                         return true;
> >                 }
> >                 if (keycode == 13) {
> >                         document.forms['searchForm'].searchButton.click();
> >                         return false;
> >                 } else {
> >                         return true;
> >                 }
> >         }
> > ...
> >     <button wicket:id="browseButton" type="submit">Browse</button>
> > ...
> >     <input wicket:id="searchTerm" maxlength="100" size="45" type="text"
> > submitEnter(this, event);" />
> > ...
> >     <button wicket:id="searchButton" type="submit"
> > id="searchButton">Search</button>
> > ...
> > -----------------------
> >
> >   I've tried both <button> and <input type="submit">, both with the same
> > result.  Wicket still reports the post as being done from the other
> > button.  Below is the page's code that deals with the buttons:
> >         add(new Button("searchButton") {
> >                 protected void onSubmit() {
> >                         search();
> >                 }
> >         });
> >         add(new Button("browseButton") {
> >                 protected void onSubmit() {
> >                         browse();
> >                 }
> >         });
> >
> >   From there, I just have a log that prints info that came from the form
> > (which seems to have been updated correctly).
> >
> >   I'm using Firefox 1.5, Wicket 1.1.
> >
> >   Are there any obvious mistakes?  Is there a way to do this?  I could
> > resort to using _javascript_ to manipulate some hidden input...
> >
> >   Thanks!
> >
> >   []s Gus
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> > files
> > for problems?  Stop!  Download the new AJAX search engine that makes
> > searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> > http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
> > _______________________________________________
> > Wicket-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
>





-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to