You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by netfork <ia...@gmail.com> on 2007/02/01 17:02:28 UTC

form's DefaultButon, Click'event is invalidation

When a form has only a TextField,
and mouse's cursor is in the TextField, 
if press enter key, form's DefaultButton's onSubmit() method is not called.



http://www.nabble.com/file/6148/screenshot.gif 
-- 
View this message in context: http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8750766
Sent from the Wicket - Dev mailing list archive at Nabble.com.


Re: form's DefaultButon, Click'event is invalidation

Posted by Igor Vaynberg <ig...@gmail.com>.
mm yes, when you press enter the button is not invoked, only the form's
onsubmit handler is invoked -- because you didnt actually press the button
:)

-igor


On 2/1/07, netfork <ia...@gmail.com> wrote:
>
>
> When a form has only a TextField,
> and mouse's cursor is in the TextField,
> if press enter key, form's DefaultButton's onSubmit() method is not
> called.
>
>
>
> http://www.nabble.com/file/6148/screenshot.gif
> --
> View this message in context:
> http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8750766
> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>
>

Re: form's DefaultButon, Click'event is invalidation

Posted by Igor Vaynberg <ig...@gmail.com>.
On 2/2/07, netfork <ia...@gmail.com> wrote:
>
> to -igor
> > mm yes, when you press enter the button is not invoked, only the form's
> > onsubmit handler is invoked -- because you didnt actually press the
> button
> > :)
> When a form has two TextFields, and cursor is in a TextField, press enter
> key, Default button's onSubmit can be called.
> others,
> if cursor is in the form, press enter key, Default button's onSubmit can
> also be called.


didnt even remember we have this setDefaultButton business tbh.

i tweaked the 1.x branch so go ahead and give it a try.

-igor






Eelco Hillenius wrote:
> >
> > On 2/1/07, Eelco Hillenius <ee...@gmail.com> wrote:
> >> You used Form#setDefaultButton ?
> >
> > You can see an example of where that works in the wizard component
> > (example abracadabra), where the default button is 'next'.
> >
> > Eelco
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8765283
> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>
>

Re: form's DefaultButon, Click'event is invalidation

Posted by netfork <ia...@gmail.com>.
to Eelco
> You used Form#setDefaultButton ? 

Yes. I used Form's setDefaultButton method.

  // Some source code:
		final CourseSelectionRule courseSelectionRuleSearch = new
CourseSelectionRule();
		final CommonMaster objSearch = new CommonMaster();
		Form form = new Form("frmCourseSelectRuleList", new
CompoundPropertyModel(courseSelectionRuleSearch));
		add(form);
... ...
		Button searchButton = new Button("searchButton") {
			protected void onSubmit() {
				setSearchCondition(courseSelectionRuleSearch, objSearch);
			}
		};
		form.add(searchButton);
		form.setDefaultButton(searchButton);
 
> You can see an example of where that works in the wizard component
> (example abracadabra), where the default button is 'next'.

abracadabra of examples has not a TextField. some pages have two TextFields.
some pages have no TextField.

My question is that the form has only one TextField.

to -igor
> mm yes, when you press enter the button is not invoked, only the form's 
> onsubmit handler is invoked -- because you didnt actually press the button 
> :) 
When a form has two TextFields, and cursor is in a TextField, press enter
key, Default button's onSubmit can be called.
others,
if cursor is in the form, press enter key, Default button's onSubmit can
also be called.




Eelco Hillenius wrote:
> 
> On 2/1/07, Eelco Hillenius <ee...@gmail.com> wrote:
>> You used Form#setDefaultButton ?
> 
> You can see an example of where that works in the wizard component
> (example abracadabra), where the default button is 'next'.
> 
> Eelco
> 
> 

-- 
View this message in context: http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8765283
Sent from the Wicket - Dev mailing list archive at Nabble.com.


Re: form's DefaultButon, Click'event is invalidation

Posted by netfork <ia...@gmail.com>.
Thanks for help!

using default button the reason is:
Only When directly press enter key or click default button(etc. Search
button) , 
page's search conditions will be saved.

When in the page change search conditions and click other button, page's
search conditions will not be saved or changed.
Page's search conditions  still are which are saved at the last time
clicking default button(or press enter key).

Now, I catch form' onSumbit event to look for clicked button. If finded
button is null, I think about the enter key is pressed.
Some source code:
		Form form = new Form("frmCourseSelectRuleList", new
CompoundPropertyModel(courseSelectionRuleSearch)) {
			protected void onSubmit() {
				Button button = this.findSubmittingButton();
				if (null == button) {
					setSearchCondition(courseSelectionRuleSearch, objSearch);  // the same
as default button' procedure
				}
			}
		};
		add(form);

... ...
		Button searchButton = new Button("searchButton") {
			protected void onSubmit() {
				setSearchCondition(courseSelectionRuleSearch, objSearch);
			}
		};
		form.add(searchButton);

		form.setDefaultButton(searchButton);

The above code may temporarily solve my problem.
If have good ideas, please tell me. Thanks a lot.



Eelco Hillenius wrote:
> 
> interesting, thanks (if it works :))
> 
> Eelco
> 
> On 2/2/07, Igor Vaynberg <ig...@gmail.com> wrote:
>> ah, but see my tweak
>>
>> now when we look for a submit button and not find one i also check for
>> the
>> default button. so if you do manage to somehow bypass the hidden field
>> and
>> submit the button it should still work.
>>
>> the "problem" i see for this is if you have the default button set and
>> submit the form using javascript form.submit(); but then i dont know if
>> you
>> really do want the default button called or not, i think you still do.
>>
>> also what i did is always move the button off screen instead of making it
>> display:none. maybe some browsers do not let you submit using hidden
>> buttons.
>>
>> -igor
>>
>>
>> On 2/2/07, Eelco Hillenius <ee...@gmail.com> wrote:
>> >
>> > On 2/2/07, netfork <ia...@gmail.com> wrote:
>> > >
>> > > test example abracadabra, also can't call default button' onSubmit
>> > method.
>> > >
>> > > Screenshot:
>> > > http://www.nabble.com/file/6211/screenshot2.gif
>> >
>> > That does work for me though...
>> >
>> > The javadoc of setDefaultButton reads:
>> >
>> >         /**
>> >          * Sets the default button. If set (not null), a hidden submit
>> > button will
>> >          * be rendered right after the form tag, so that when users
>> press
>> > enter in a
>> >          * textfield, this button's action will be selected. If no
>> default
>> > button is
>> >          * set (so unset by calling this method with null), nothing
>> > additional is
>> >          * rendered.
>> >          * <p>
>> >          * WARNING: note that this is a best effort only. Unfortunately
>> > having a
>> >          * 'default' button in a form is ill defined in the standards,
>> and
>> > of course
>> >          * IE has it's own way of doing things.
>> >          * </p>
>> >          *
>> >          * @param button
>> >          *            The button to set as the default button, or null
>> > when you want
>> >          *            to 'unset' any previously set default button
>> >          */
>> >
>> > Note the warning. The tactic I used I to put a submit button field
>> > right after the form declaration in HTML and hide it (e.g. in the
>> > wizard: <input type="submit" value="Next &gt;" name="buttons:next"
>> > style="display: none" />). Unfortunately, HTML doesn't have the
>> > concept of a default button. The heuristic in this case is that if you
>> > press enter in a text field, most if not all browsers will choose the
>> > first button that was defined in the form.
>> >
>> > Doing it with javascript (catching onkeypressed or something similar)
>> > would be too intrusive for the framework, though it might be a good
>> > solution for your specific case.
>> >
>> > Eelco
>> >
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8778573
Sent from the Wicket - Dev mailing list archive at Nabble.com.


Re: form's DefaultButon, Click'event is invalidation

Posted by Eelco Hillenius <ee...@gmail.com>.
interesting, thanks (if it works :))

Eelco

On 2/2/07, Igor Vaynberg <ig...@gmail.com> wrote:
> ah, but see my tweak
>
> now when we look for a submit button and not find one i also check for the
> default button. so if you do manage to somehow bypass the hidden field and
> submit the button it should still work.
>
> the "problem" i see for this is if you have the default button set and
> submit the form using javascript form.submit(); but then i dont know if you
> really do want the default button called or not, i think you still do.
>
> also what i did is always move the button off screen instead of making it
> display:none. maybe some browsers do not let you submit using hidden
> buttons.
>
> -igor
>
>
> On 2/2/07, Eelco Hillenius <ee...@gmail.com> wrote:
> >
> > On 2/2/07, netfork <ia...@gmail.com> wrote:
> > >
> > > test example abracadabra, also can't call default button' onSubmit
> > method.
> > >
> > > Screenshot:
> > > http://www.nabble.com/file/6211/screenshot2.gif
> >
> > That does work for me though...
> >
> > The javadoc of setDefaultButton reads:
> >
> >         /**
> >          * Sets the default button. If set (not null), a hidden submit
> > button will
> >          * be rendered right after the form tag, so that when users press
> > enter in a
> >          * textfield, this button's action will be selected. If no default
> > button is
> >          * set (so unset by calling this method with null), nothing
> > additional is
> >          * rendered.
> >          * <p>
> >          * WARNING: note that this is a best effort only. Unfortunately
> > having a
> >          * 'default' button in a form is ill defined in the standards, and
> > of course
> >          * IE has it's own way of doing things.
> >          * </p>
> >          *
> >          * @param button
> >          *            The button to set as the default button, or null
> > when you want
> >          *            to 'unset' any previously set default button
> >          */
> >
> > Note the warning. The tactic I used I to put a submit button field
> > right after the form declaration in HTML and hide it (e.g. in the
> > wizard: <input type="submit" value="Next &gt;" name="buttons:next"
> > style="display: none" />). Unfortunately, HTML doesn't have the
> > concept of a default button. The heuristic in this case is that if you
> > press enter in a text field, most if not all browsers will choose the
> > first button that was defined in the form.
> >
> > Doing it with javascript (catching onkeypressed or something similar)
> > would be too intrusive for the framework, though it might be a good
> > solution for your specific case.
> >
> > Eelco
> >
>
>

Re: form's DefaultButon, Click'event is invalidation

Posted by Igor Vaynberg <ig...@gmail.com>.
ah, but see my tweak

now when we look for a submit button and not find one i also check for the
default button. so if you do manage to somehow bypass the hidden field and
submit the button it should still work.

the "problem" i see for this is if you have the default button set and
submit the form using javascript form.submit(); but then i dont know if you
really do want the default button called or not, i think you still do.

also what i did is always move the button off screen instead of making it
display:none. maybe some browsers do not let you submit using hidden
buttons.

-igor


On 2/2/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 2/2/07, netfork <ia...@gmail.com> wrote:
> >
> > test example abracadabra, also can't call default button' onSubmit
> method.
> >
> > Screenshot:
> > http://www.nabble.com/file/6211/screenshot2.gif
>
> That does work for me though...
>
> The javadoc of setDefaultButton reads:
>
>         /**
>          * Sets the default button. If set (not null), a hidden submit
> button will
>          * be rendered right after the form tag, so that when users press
> enter in a
>          * textfield, this button's action will be selected. If no default
> button is
>          * set (so unset by calling this method with null), nothing
> additional is
>          * rendered.
>          * <p>
>          * WARNING: note that this is a best effort only. Unfortunately
> having a
>          * 'default' button in a form is ill defined in the standards, and
> of course
>          * IE has it's own way of doing things.
>          * </p>
>          *
>          * @param button
>          *            The button to set as the default button, or null
> when you want
>          *            to 'unset' any previously set default button
>          */
>
> Note the warning. The tactic I used I to put a submit button field
> right after the form declaration in HTML and hide it (e.g. in the
> wizard: <input type="submit" value="Next &gt;" name="buttons:next"
> style="display: none" />). Unfortunately, HTML doesn't have the
> concept of a default button. The heuristic in this case is that if you
> press enter in a text field, most if not all browsers will choose the
> first button that was defined in the form.
>
> Doing it with javascript (catching onkeypressed or something similar)
> would be too intrusive for the framework, though it might be a good
> solution for your specific case.
>
> Eelco
>

Re: form's DefaultButon, Click'event is invalidation

Posted by Eelco Hillenius <ee...@gmail.com>.
On 2/2/07, netfork <ia...@gmail.com> wrote:
>
> test example abracadabra, also can't call default button' onSubmit method.
>
> Screenshot:
> http://www.nabble.com/file/6211/screenshot2.gif

That does work for me though...

The javadoc of setDefaultButton reads:

	/**
	 * Sets the default button. If set (not null), a hidden submit button will
	 * be rendered right after the form tag, so that when users press enter in a
	 * textfield, this button's action will be selected. If no default button is
	 * set (so unset by calling this method with null), nothing additional is
	 * rendered.
	 * <p>
	 * WARNING: note that this is a best effort only. Unfortunately having a
	 * 'default' button in a form is ill defined in the standards, and of course
	 * IE has it's own way of doing things.
	 * </p>
	 *
	 * @param button
	 *            The button to set as the default button, or null when you want
	 *            to 'unset' any previously set default button
	 */

Note the warning. The tactic I used I to put a submit button field
right after the form declaration in HTML and hide it (e.g. in the
wizard: <input type="submit" value="Next &gt;" name="buttons:next"
style="display: none" />). Unfortunately, HTML doesn't have the
concept of a default button. The heuristic in this case is that if you
press enter in a text field, most if not all browsers will choose the
first button that was defined in the form.

Doing it with javascript (catching onkeypressed or something similar)
would be too intrusive for the framework, though it might be a good
solution for your specific case.

Eelco

Re: form's DefaultButon, Click'event is invalidation

Posted by netfork <ia...@gmail.com>.
test example abracadabra, also can't call default button' onSubmit method.

Screenshot:
http://www.nabble.com/file/6211/screenshot2.gif 


Eelco Hillenius wrote:
> 
> On 2/1/07, Eelco Hillenius  wrote:
>> You used Form#setDefaultButton ?
> 
> You can see an example of where that works in the wizard component
> (example abracadabra), where the default button is 'next'.
> 
> Eelco
> 
> 
-- 
View this message in context: http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8765612
Sent from the Wicket - Dev mailing list archive at Nabble.com.

Re: form's DefaultButon, Click'event is invalidation

Posted by Eelco Hillenius <ee...@gmail.com>.
On 2/1/07, Eelco Hillenius <ee...@gmail.com> wrote:
> You used Form#setDefaultButton ?

You can see an example of where that works in the wizard component
(example abracadabra), where the default button is 'next'.

Eelco

Re: form's DefaultButon, Click'event is invalidation

Posted by Eelco Hillenius <ee...@gmail.com>.
You used Form#setDefaultButton ?

Eelco

On 2/1/07, netfork <ia...@gmail.com> wrote:
>
> When a form has only a TextField,
> and mouse's cursor is in the TextField,
> if press enter key, form's DefaultButton's onSubmit() method is not called.
>
>
>
> http://www.nabble.com/file/6148/screenshot.gif
> --
> View this message in context: http://www.nabble.com/form%27s-DefaultButon%2C-Click%27event-is-invalidation-tf3155687.html#a8750766
> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>
>