+ Start a Discussion
MMA_FORCEMMA_FORCE 

Can I do checkbox in VF this way????

Hi:

   I have a checkbox named advanceFilter and if checked would like an entire row to appear...

But somehow it is not working with my current statement :

 

<td>AdvanceFilter<input type="checkbox" name="AdvanceFilter" id="af"/></td> </tr> <tr><td> <input type="checkbox" name="AdvanceFilter" rendered="{!$Component.theform.AdvanceFilter='true'}"/> </td></tr>

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

{!$Component.theform.the_checkbox} generates the id of the input checkbox on the page.

 

If you want to get the value of the checkbox, you'll need something in Javascript like:

 

document.getElementById('{!$Component.theform.the_checkbox}').value 

 

All Answers

bob_buzzardbob_buzzard
No, you can't do that.  You are mixing regular HTML input components with VF attributes - e.g. the HTML checkbox input doesn't have a concept of rendered.
MMA_FORCEMMA_FORCE

Is there a way to show a table based off a checkbox? Does anyone have an example of this...

Thanks

Anand@SAASAnand@SAAS
use the "onClick" handler with <apex:actionRegion> and the re-render capability. There should be examples in the visual force documentation.
MMA_FORCEMMA_FORCE

Thank You Anand...

 So I have done this but does not seem to be working what am I doing incorrect?

 

<td> AdvanceFilter: <input type="checkbox" name="the_checkbox" value="ok" /> <apex:actionSupport event="onClick" reRender="{!$Component.theform.hello}" status="testStatus" /> </td> </tr> <apex:actionStatus id="testStatus" startText="Loading" /> <apex:actionRegion rendered="{!$Component.theform.the_checkbox.value='ok'}" > <table id="hello"> <tr> <td>meal: <input type="checkbox" name="meal" value="salad" /></td> </tr> </table> </apex:actionRegion>

 

 

 

bob_buzzardbob_buzzard

actionsupport has to be embedded inside another apex component to have any effect.

 

You'll need to change your regular HTML checkbox to an inputCheckbox component and nest the actionsupport inside that. 

MMA_FORCEMMA_FORCE

Yeah but for an inputcheckbox the VF Tag I need to place in the value and bind it to a field...

This is a reporting tool I am creating so I can not have it bind to any field but itself...

 

How would I go around that? 

bob_buzzardbob_buzzard
You don't have to bind it to a field - just don't supply a value attribute.
MMA_FORCEMMA_FORCE

Thank you for that  Bob...

But now that I did that, nothing happens:

 

<td> AdvanceFilter: <apex:inputCheckbox id="the_checkbox" title="Advance Filter"/> <apex:actionSupport event="onClick" reRender="{!$Component.theform.hello}" status="testStatus" /> </td> </tr> <apex:actionStatus id="testStatus" startText="Loading" /> <apex:actionRegion rendered="{!$Component.theform.the_checkbox}" > <table id="hello"> <tr> <td>meal: <apex:inputCheckbox id="meal" /></td> </tr> </table> </apex:actionRegion>

 

 

 

bob_buzzardbob_buzzard
Your actionsupport still isn't nested inside your inputcheckbox component - its simply below it. 
MMA_FORCEMMA_FORCE

ok... So now I did this: and nothing happen??? am I missing something

 

<td> <apex:actionSupport event="onClick" reRender="{!$Component.theform.hello}" status="testStatus" > AdvanceFilter: <apex:inputCheckbox id="the_checkbox" title="Advance Filter"/> </apex:actionSupport> </td> </tr> <apex:actionStatus id="testStatus" startText="Loading" /> <apex:actionRegion rendered="{!$Component.theform.the_checkbox}" > <table id="hello"> <tr> <td>meal: <apex:inputCheckbox id="meal" /></td> </tr> </table> </apex:actionRegion>

 I even tried:nothing???

 <td>

<apex:actionSupport event="onClick" reRender="{!$Component.theform.helloregion.
hello}" status="testStatus" >
AdvanceFilter: <apex:inputCheckbox id="the_checkbox" title="Advance Filter"/>
</apex:actionSupport>
</td>
</tr>
<apex:actionStatus id="testStatus" startText="Loading" />
<apex:actionRegion rendered="{!$Component.theform.the_checkbox}" id="helloregion" >

<table id="hello">
<tr>
<td>meal: <apex:inputCheckbox id="meal" /></td>

</tr>
</table>
</apex:actionRegion>
 

 

bob_buzzardbob_buzzard

You still haven't nested actionsupport inside your inputcheckbox.  You've nested inputcheckbox inside your actionsupport.

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionSupport.htm

 

As you can see, actionsupport goes inside the component that you wish to add the behaviour to.  In the linked example, its adding actionsupport to the  outputpanel.

 

 

MMA_FORCEMMA_FORCE

Thank you ... I did do that and I see it work with the exception that it does not show the table??

 

<apex:outputpanel id="counter"> <apex:inputCheckbox id="the_checkbox"/> <apex:actionSupport event="onclick" rerender="counter" status="counterStatus"/> <apex:actionStatus id="counterStatus" startText=" (loading filters...)" /> <apex:actionRegion rendered="{!$Component.theform.the_checkbox}"> <table id="hello"> <tr> <td>Special Education: <apex:inputCheckbox id="specialeducation" /></td> <td>Student Free Lunch: <apex:inputCheckbox id="StudentFreeLunch" /></td> </tr> </table> </apex:actionRegion> </apex:outputpanel> </td> </tr>

 

 

 

bob_buzzardbob_buzzard
I don't think your rendered logic is correct - you are just using the id of the_checkbox, rather than retrieving the checkboxes value.
MMA_FORCEMMA_FORCE

All I want it to do is simple:

If the_checkbox=true which is if the user clicks on it and it is checked

 

show the table

 

if not then do not show it...

 

I tried:

{!$Component.theform.the_checkbox='true'}

 

did not work?

How can u check if the checkbox is true or checked to render that region ?

bob_buzzardbob_buzzard

{!$Component.theform.the_checkbox} generates the id of the input checkbox on the page.

 

If you want to get the value of the checkbox, you'll need something in Javascript like:

 

document.getElementById('{!$Component.theform.the_checkbox}').value 

 

This was selected as the best answer
MMA_FORCEMMA_FORCE
Thank you sooooo much Bob... That is what I needed.. Your awesome... Thanks