You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by sorinev <so...@gmail.com> on 2015/06/12 23:14:07 UTC

TextField -> AjaxEventBehavior-onBlur -> onEvent

Wicket v1.4.17

I have a Form with a TextField and, among other things, two submit buttons.
One is a typical submit button, the other is a submit button that acts as a
cancel (closes stuff out and goes to the previous page). 

This TextField has an AjaxEventBehavior of onBlur added to it, and inside
that behavior, onEvent is overridden. onEvent does some validation of the
TextField's contents and dynamically updates some stuff on the page.
Meaning, when the TextField loses focus, it's going to immediately update a
table on the page. 

The problem, however, is that the TextField has DefaultFocusBehavior on it
as well so that when you first visit the page, the TextField already has
focus. So upon first visiting the page, if you try to click either of the
submit buttons (well, the "cancel" submit button really, because the other
submit button is disabled until the TextField gets input), you have to click
it twice before it activates. The first click does nothing, i.e., the
onSubmit method doesn't fire.

This appears to be caused by the onBlur/onEvent deal, because clicking the
button means the TextField has lost focus, but it somehow results in that
click not registering. 

Of course, commenting out the DefaultFocusBehavior line makes everything
work fine since the TextField doesn't have focus on the first visit to the
page, but since having focus on the TextField is our desired behavior, is
there a way to make this work? 

Between NetBeans code completion in source and messing around in the
debugger, I couldn't see a way to find out which component, if any, was
clicked in order to trigger the onBlur/onEvent. That would be easy because I
could see if it was the cancel button, and if so, I could trigger it's
onSubmit (if that's actually even possible). I also didn't see any methods
available to any component while inside the onEvent method that would help
me get this working right. 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by Martin Grigorov <mg...@apache.org>.
Welcome!

Martin Grigorov
Freelancer. Available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jun 16, 2015 at 7:18 PM, sorinev <so...@gmail.com> wrote:

> False alarm, I had some kinks to work out. It works great now, thanks for
> your help with this, I appreciate it.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671204.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by sorinev <so...@gmail.com>.
False alarm, I had some kinks to work out. It works great now, thanks for
your help with this, I appreciate it. 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671204.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by sorinev <so...@gmail.com>.
How would I accomplish that? I've tried

this  https://cwiki.apache.org/confluence/display/WICKET/Markup+inheritance
<https://cwiki.apache.org/confluence/display/WICKET/Markup+inheritance>  

and this 
https://cwiki.apache.org/confluence/display/WICKET/Adding+Javascript+or+CSS+using+a+Resource
<https://cwiki.apache.org/confluence/display/WICKET/Adding+Javascript+or+CSS+using+a+Resource>  

and neither is working. 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671203.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by Martin Grigorov <mg...@apache.org>.
OK. This is what you mean by highlighting. I imagined something else.
In this case you can use JavaScript to accomplish this without using Wicket:

$(document).on('focusin', '#yourTableId td input', function()
{$(this).select();})

Martin Grigorov
Freelancer. Available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jun 16, 2015 at 5:09 PM, sorinev <so...@gmail.com> wrote:

> I don't have the code at hand this very moment, but it goes something like
> this.
>
> The TextField above the table does the onblur like:
>
> tf.add(new AjaxEventBehavior("onBlur", {override onEvent here along with a
> target.addComponent(table)} ...
>
> Then for the table, there is a DataView with a populate item. In populate
> item, those TextFields get setup like:
>
> item.add(new SimpleAttributeModifier("onfocus", "this.select(); return
> true;");
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671194.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by sorinev <so...@gmail.com>.
I don't have the code at hand this very moment, but it goes something like
this. 

The TextField above the table does the onblur like:

tf.add(new AjaxEventBehavior("onBlur", {override onEvent here along with a
target.addComponent(table)} ...

Then for the table, there is a DataView with a populate item. In populate
item, those TextFields get setup like:

item.add(new SimpleAttributeModifier("onfocus", "this.select(); return
true;");



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671194.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

How exactly do you use SimpleAttributeModifier here?
I think using CSS like: input:focus {...} should be good enough for
highlighting the currently focused <input>. No need of extra logic.

Martin Grigorov
Freelancer. Available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jun 16, 2015 at 1:31 AM, sorinev <so...@gmail.com> wrote:

> I decoupled the submit buttons from the table, which was easy on the Java
> side but a HUGE pain on the HTML side. However, I now have a new problem
> (well it always existed, but it's next on the agenda).
>
> This form has a TextField and a table. The table has some rows on it, and
> each row has a couple of TextFields on it. Each of the TextFields on the
> table has a SimpleAttributeModifier that, upon focus, highlights the
> contents of the box.
>
> BUT, the TextField at the top of the form has an onBlur set to it. This
> means that when you click away from the TextField at the top, and into one
> of the tables TextFields, the contents of the table TextField will briefly
> flash blue (highlighted), but then a split second after that the contents
> are no longer highlighted and the cursor is at the beginning of the
> TextField. This seems to obviously be because in the main TextField's
> onblur, the table is added (no getting around that in this case). So the
> table TextField's onfocus is basically nullified as a result. Also, it
> seems
> that the onfocus of the table TextField fires before the main TextField's
> onblur, which kills the one idea I had (grab the row and textfield IDs on
> the onfocus, then in the onblur, after adding the table, set the focus
> back).
>
> So how can I keep the content of the TextField that's clicked into
> highlighted even after that TextField is added back onto the page via
> another component's onblur?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671174.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by sorinev <so...@gmail.com>.
I decoupled the submit buttons from the table, which was easy on the Java
side but a HUGE pain on the HTML side. However, I now have a new problem
(well it always existed, but it's next on the agenda). 

This form has a TextField and a table. The table has some rows on it, and
each row has a couple of TextFields on it. Each of the TextFields on the
table has a SimpleAttributeModifier that, upon focus, highlights the
contents of the box. 

BUT, the TextField at the top of the form has an onBlur set to it. This
means that when you click away from the TextField at the top, and into one
of the tables TextFields, the contents of the table TextField will briefly
flash blue (highlighted), but then a split second after that the contents
are no longer highlighted and the cursor is at the beginning of the
TextField. This seems to obviously be because in the main TextField's
onblur, the table is added (no getting around that in this case). So the
table TextField's onfocus is basically nullified as a result. Also, it seems
that the onfocus of the table TextField fires before the main TextField's
onblur, which kills the one idea I had (grab the row and textfield IDs on
the onfocus, then in the onblur, after adding the table, set the focus
back). 

So how can I keep the content of the TextField that's clicked into
highlighted even after that TextField is added back onto the page via
another component's onblur? 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150p4671174.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: TextField -> AjaxEventBehavior-onBlur -> onEvent

Posted by Sven Meier <sv...@meiers.net>.
Hi,

>This appears to be caused by the onBlur/onEvent deal, because clicking the
>button means the TextField has lost focus, but it somehow results in that
>click not registering.

there are two reasons why "click/submit" might not trigger on your button:

- your AjaxEventBehavior is adding the button (or its parents) to the AjaxRequestTarget
- updating the table shifts the position the button on the page, so the button is no longer under the mouse when the user releases the press

Regards
Sven


On 12.06.2015 23:14, sorinev wrote:
> Wicket v1.4.17
>
> I have a Form with a TextField and, among other things, two submit buttons.
> One is a typical submit button, the other is a submit button that acts as a
> cancel (closes stuff out and goes to the previous page).
>
> This TextField has an AjaxEventBehavior of onBlur added to it, and inside
> that behavior, onEvent is overridden. onEvent does some validation of the
> TextField's contents and dynamically updates some stuff on the page.
> Meaning, when the TextField loses focus, it's going to immediately update a
> table on the page.
>
> The problem, however, is that the TextField has DefaultFocusBehavior on it
> as well so that when you first visit the page, the TextField already has
> focus. So upon first visiting the page, if you try to click either of the
> submit buttons (well, the "cancel" submit button really, because the other
> submit button is disabled until the TextField gets input), you have to click
> it twice before it activates. The first click does nothing, i.e., the
> onSubmit method doesn't fire.
>
> This appears to be caused by the onBlur/onEvent deal, because clicking the
> button means the TextField has lost focus, but it somehow results in that
> click not registering.
>
> Of course, commenting out the DefaultFocusBehavior line makes everything
> work fine since the TextField doesn't have focus on the first visit to the
> page, but since having focus on the TextField is our desired behavior, is
> there a way to make this work?
>
> Between NetBeans code completion in source and messing around in the
> debugger, I couldn't see a way to find out which component, if any, was
> clicked in order to trigger the onBlur/onEvent. That would be easy because I
> could see if it was the cancel button, and if so, I could trigger it's
> onSubmit (if that's actually even possible). I also didn't see any methods
> available to any component while inside the onEvent method that would help
> me get this working right.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/TextField-AjaxEventBehavior-onBlur-onEvent-tp4671150.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org