You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by divad91 <di...@hotmail.com> on 2013/02/13 19:32:34 UTC
AjaxEventBehavior called twice because of javascript onchange
Hi,
I using wicket 1.4.21 and developing an application that needs to work in
IE7 and +., firefox, chrome etc.
I have a problem with IE. Ajax "listener" are called twice because I have
javascript that remove the dropdown default empty option "Choose One".
My ajax listener is called on first time and then the javascript is removing
the default option causing my Ajax listener being called again.
This problems occurs only in IE.
This is not really related to wicket but I was wondering if anyone had this
problems before.
** My clients want the "Choose One" option so I can't just put a default
value to the drop down.
Thanks for help.
David
Java code
Javacript code :
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329.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: AjaxEventBehavior called twice because of javascript onchange
Posted by divad91 <di...@hotmail.com>.
My mistake, I works great with the nullvalid.
I just realize that if I have an "onchange behavior" and a javascript
(jQuery) onchange function bind on the same dropdown, with IE, calling the
javascript onchange function will also call the wicket onchange behavior.
Can't figure out why.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656413.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: AjaxEventBehavior called twice because of javascript onchange
Posted by divad91 <di...@hotmail.com>.
Thanks Sauli your solution works !
But i still have the problem (with an other dropdown) even if I remove the
javascript that remove the empty option or if I set the nullvalid to the
dropdown list.
The only particularity that I see is that the dropdown is in a
AjaxWebMarkupContainer. A lots of component in my page are refreshing the
ajax container. Looks like the onChange event is bind multiple time on every
ajax "refresh"..
ILL continue to investigate...
Thanks.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656411.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: AjaxEventBehavior called twice because of javascript onchange
Posted by divad91 <di...@hotmail.com>.
Thanks for the info. I will try it rigth aways.
I will let know know if it works.
David
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656378.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: AjaxEventBehavior called twice because of javascript onchange
Posted by "sauli.ketola" <sa...@mbnet.fi>.
Hi,
Could you instead use this:
See
http://wicket.apache.org/apidocs/1.4/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.html#setNullValid%28boolean%29
"If set to false, then "Choose One" will be displayed when the value is
null. After a value is selected, and that change is propagated to the
underlying model, the user will no longer see the "Choose One" option"
With that, after you post the form the "Choose One" is removed. Or you could
save the value to the model of the dropdown inside the onchange behavior,
and the add the dropdown to the AjaxRequestTarget causing the dropdown to
refresh and the "Choose One" to be removed.
- Sauli
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656350.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: AjaxEventBehavior called twice because of javascript onchange
Posted by Sven Meier <sv...@meiers.net>.
Hi,
your code didn't come through with you initial post.
Regretfully I don't have an idea what's going wrong here: Removing an
option via Javascript shouldn't trigger any change event handler.
Sven
On 02/13/2013 08:56 PM, divad91 wrote:
> The code is in my first post at the end.
>
> With jQuery 1.6.1
> enhanceComboBoxes : function enhanceComboBoxes() {
> var comboboxes = $("select:not(.emptyOptionEnhanced,
> .noRemoveEmptyChoice)");
> comboboxes.each(function() {
> var combo = $(this);
> var emptyOptions = combo.find("option[value='']");
>
> if (emptyOptions.length) {
> combo.debug("Enhancing combo box with empty option");
> combo.change(function(e) {
> emptyOptions.debug("Removing empty option").remove();
> });
> ).addClass("emptyOptionEnhanced");
> },
>
> The enhanceComboBoxes function is called after each ajax call.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656334.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
Re: AjaxEventBehavior called twice because of javascript onchange
Posted by divad91 <di...@hotmail.com>.
The code is in my first post at the end.
With jQuery 1.6.1
enhanceComboBoxes : function enhanceComboBoxes() {
var comboboxes = $("select:not(.emptyOptionEnhanced,
.noRemoveEmptyChoice)");
comboboxes.each(function() {
var combo = $(this);
var emptyOptions = combo.find("option[value='']");
if (emptyOptions.length) {
combo.debug("Enhancing combo box with empty option");
combo.change(function(e) {
emptyOptions.debug("Removing empty option").remove();
});
).addClass("emptyOptionEnhanced");
},
The enhanceComboBoxes function is called after each ajax call.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656334.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: AjaxEventBehavior called twice because of javascript onchange
Posted by Sven Meier <sv...@meiers.net>.
How do you remove the option? Show us some code.
Sven
On 02/13/2013 08:22 PM, divad91 wrote:
> More precisely, removing an option of a dropdown list with Internet Explorer
> (IE7 - IE8) triggers the Wicket Onchange Behavior.
>
> Any workaround too avoid this ?
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656330.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
Re: AjaxEventBehavior called twice because of javascript onchange
Posted by divad91 <di...@hotmail.com>.
More precisely, removing an option of a dropdown list with Internet Explorer
(IE7 - IE8) triggers the Wicket Onchange Behavior.
Any workaround too avoid this ?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxEventBehavior-called-twice-because-of-javascript-onchange-tp4656329p4656330.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