You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Colman <ch...@stepaheadsoftware.com> on 2012/05/31 08:20:16 UTC

Is there a quick way to deselect all radio buttons in a group via an AJAX event?

We have a button that, when clicked, should deselect ALL radio buttons
in a separate radio group.
 
Can this be done in Wicket?
 
Yours sincerely,
 
Chris Colman
 
Pagebloom Team Leader,
Step Ahead Software

 
pagebloom - your business & your website growing together
 
Sydney: (+61 2) 9656 1278     Canberra: (+61 2) 6100 2120     
Email: chrisc@stepahead.com.au <ma...@stepahead.com.au> 
Website:
http://www.pagebloom.com <blocked::http://www.pagebloom.com/> 
http://develop.stepaheadsoftware.com
<blocked::http://develop.stepaheadsoftware.com/> 
 
 

RE: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
>@Chris: Can't you reset the RadioGroup's model so that none of the
>Radios models match and re-render the whole group ?

That's what I tried first but it didn't work for some reason.

 
>
>>
>>   -Tom
>>
>>
>>
>> On 31.05.2012 at 08:20 Chris Colman wrote:
>>
>>> We have a button that, when clicked, should deselect ALL radio buttons
>in a separate radio group.
>>>
>>> Can this be done in Wicket?
>>>
>>> Yours sincerely,
>>>
>>> Chris Colman
>>
>
>
>
>--
>Martin Grigorov
>jWeekend
>Training, Consulting, Development
>http://jWeekend.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: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
>> <span wicket:id="radioGroup1">
>>        <div wicket:id="radioGroup1Div">
>>                <input id="choice1" name="option1" type="radio"
>> value="01" wicket:id="choice1">
>>                <input id="choice2" name="option1" type="radio"
>> value="02" wicket:id="choice2">
>>
>>
>>        </div>
>> </span>
>
><div> inside <span> is invalid HTML. I know that one of those is not
>rendered at all because it is attached to the RadioGroup but ...
>can't you do radioGroup.setRenderBodyOnly(false) and remove the extra
>component ?

Hmmm, probably could do it that way.

>
>
>>
>>>>@Chris: Can't you reset the RadioGroup's model so that none of the
>>>>Radios models match and re-render the whole group ?
>>>
>>>Bingo! I got it working.
>>>
>>>I wasn't adding the radio button to the target in the event handler.
>>>
>>>This is what works:
>>>
>>>       group2Choice1Radio.add(new AjaxEventBehavior("onclick") {
>>>               @Override
>>>               protected void onEvent(AjaxRequestTarget target) {
>>>                       // there is no radio button for o1None so
>>>choosing this
>>>                       // deselects all radio buttons
>>>                       setGroup1Option(new Integer(MyModel.o1None));
>>>target.add(group1Choice1Radio);
>>>                       target.add(group1Choice2Radio);
>>>               }
>>>       });
>>>
>>>Using this option I need to target.add() for each individual radio
>>>button in the group I want to have deselected.
>>>
>>>I tried using the RadioGroup object as the component added to the
>> target
>>>like:
>>>
>>>target.add(option1Group);
>>>
>>>but got:
>>>
>>>Last cause: Ajax render cannot be called on component that has
>>>setRenderBodyOnly enabled. Component: [RadioGroup [Component id =
>>>option1Group]]
>>>
>>>Which makes sense because the RadioGroup component's tags disappear
>> when
>>>the markup is rendered.
>>>
>>>Regards,
>>>Chris
>>>
>>>---------------------------------------------------------------------
>>>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
>>
>
>
>
>--
>Martin Grigorov
>jWeekend
>Training, Consulting, Development
>http://jWeekend.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: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, May 31, 2012 at 11:48 AM, Chris Colman
<ch...@stepaheadsoftware.com> wrote:
> Doh! That approach fails when I target.add a second radio button.
>
> I needed to create a new MarkupContainer to wrap the group in and then I
> target.add() that div and deselection of all items works well.
>
> So it looks like this:
>
> <span wicket:id="radioGroup1">
>        <div wicket:id="radioGroup1Div">
>                <input id="choice1" name="option1" type="radio"
> value="01" wicket:id="choice1">
>                <input id="choice2" name="option1" type="radio"
> value="02" wicket:id="choice2">
>
>
>        </div>
> </span>

<div> inside <span> is invalid HTML. I know that one of those is not
rendered at all because it is attached to the RadioGroup but ...
can't you do radioGroup.setRenderBodyOnly(false) and remove the extra
component ?


>
>>>@Chris: Can't you reset the RadioGroup's model so that none of the
>>>Radios models match and re-render the whole group ?
>>
>>Bingo! I got it working.
>>
>>I wasn't adding the radio button to the target in the event handler.
>>
>>This is what works:
>>
>>       group2Choice1Radio.add(new AjaxEventBehavior("onclick") {
>>               @Override
>>               protected void onEvent(AjaxRequestTarget target) {
>>                       // there is no radio button for o1None so
>>choosing this
>>                       // deselects all radio buttons
>>                       setGroup1Option(new Integer(MyModel.o1None));
>>target.add(group1Choice1Radio);
>>                       target.add(group1Choice2Radio);
>>               }
>>       });
>>
>>Using this option I need to target.add() for each individual radio
>>button in the group I want to have deselected.
>>
>>I tried using the RadioGroup object as the component added to the
> target
>>like:
>>
>>target.add(option1Group);
>>
>>but got:
>>
>>Last cause: Ajax render cannot be called on component that has
>>setRenderBodyOnly enabled. Component: [RadioGroup [Component id =
>>option1Group]]
>>
>>Which makes sense because the RadioGroup component's tags disappear
> when
>>the markup is rendered.
>>
>>Regards,
>>Chris
>>
>>---------------------------------------------------------------------
>>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
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


RE: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
Doh! That approach fails when I target.add a second radio button.

I needed to create a new MarkupContainer to wrap the group in and then I
target.add() that div and deselection of all items works well.

So it looks like this:

<span wicket:id="radioGroup1">
	<div wicket:id="radioGroup1Div">
		<input id="choice1" name="option1" type="radio"
value="01" wicket:id="choice1">
		<input id="choice2" name="option1" type="radio"
value="02" wicket:id="choice2">

		
	</div>
</span>

>>@Chris: Can't you reset the RadioGroup's model so that none of the
>>Radios models match and re-render the whole group ?
>
>Bingo! I got it working.
>
>I wasn't adding the radio button to the target in the event handler.
>
>This is what works:
>
>	group2Choice1Radio.add(new AjaxEventBehavior("onclick") {
>		@Override
>		protected void onEvent(AjaxRequestTarget target) {
>			// there is no radio button for o1None so
>choosing this
>			// deselects all radio buttons
>			setGroup1Option(new Integer(MyModel.o1None));
>target.add(group1Choice1Radio);
>			target.add(group1Choice2Radio);
>		}
>	});
>
>Using this option I need to target.add() for each individual radio
>button in the group I want to have deselected.
>
>I tried using the RadioGroup object as the component added to the
target
>like:
>
>target.add(option1Group);
>
>but got:
>
>Last cause: Ajax render cannot be called on component that has
>setRenderBodyOnly enabled. Component: [RadioGroup [Component id =
>option1Group]]
>
>Which makes sense because the RadioGroup component's tags disappear
when
>the markup is rendered.
>
>Regards,
>Chris
>
>---------------------------------------------------------------------
>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: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

Posted by Chris Colman <ch...@stepaheadsoftware.com>.
>@Chris: Can't you reset the RadioGroup's model so that none of the
>Radios models match and re-render the whole group ?

Bingo! I got it working.

I wasn't adding the radio button to the target in the event handler.

This is what works:

	group2Choice1Radio.add(new AjaxEventBehavior("onclick") {
		@Override
		protected void onEvent(AjaxRequestTarget target) {
			// there is no radio button for o1None so
choosing this
			// deselects all radio buttons
			setGroup1Option(new Integer(MyModel.o1None));
target.add(group1Choice1Radio);
			target.add(group1Choice2Radio);		
		}
	});

Using this option I need to target.add() for each individual radio
button in the group I want to have deselected.

I tried using the RadioGroup object as the component added to the target
like:

target.add(option1Group); 

but got:

Last cause: Ajax render cannot be called on component that has
setRenderBodyOnly enabled. Component: [RadioGroup [Component id =
option1Group]]

Which makes sense because the RadioGroup component's tags disappear when
the markup is rendered.

Regards,
Chris

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


Re: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

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

On Thu, May 31, 2012 at 10:04 AM, Thomas Götz <to...@decoded.de> wrote:
> What about using Javascript? e.g. jQuery:
>
> $('input:radio').attr('checked', false);
>
> or
>
> $('input[name=myRadio]:radio').attr('checked', false);
>

I guess he will need to update the server state as well.

@Chris: Can't you reset the RadioGroup's model so that none of the
Radios models match and re-render the whole group ?

>
>   -Tom
>
>
>
> On 31.05.2012 at 08:20 Chris Colman wrote:
>
>> We have a button that, when clicked, should deselect ALL radio buttons in a separate radio group.
>>
>> Can this be done in Wicket?
>>
>> Yours sincerely,
>>
>> Chris Colman
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Is there a quick way to deselect all radio buttons in a group via an AJAX event?

Posted by Thomas Götz <to...@decoded.de>.
What about using Javascript? e.g. jQuery:

$('input:radio').attr('checked', false);

or

$('input[name=myRadio]:radio').attr('checked', false);


   -Tom



On 31.05.2012 at 08:20 Chris Colman wrote:

> We have a button that, when clicked, should deselect ALL radio buttons in a separate radio group.
>  
> Can this be done in Wicket?
>  
> Yours sincerely,
>  
> Chris Colman