You need to sign in to do that
Don't have an account?
Checkbox checked on page load in a list
Guys, I am little confused. I want to set checkbox on page load in a list of records.
I am rendering a list (of Engagement records) on a custom page. The first column of list is a checkbox. This checkbox should be checked on page load if Engagement record has atleast one related Potential record.
I tried using inputCheckbox and tried to use selected attribute but it did not work.
I tried using then HTML input checkbox field and tried to use 'checked'
<input id="{!engagement.Id}" value="{!engagement.Id}" type="checkbox" class="checkbox" name="ids" {!IF( ISBLANK(engagement.Potential__r), '', 'checked')} />
but VisualForce starts giving error. I am not able to set checkbox on page load. Can anyone provide any clue of how this can be done.
You need somewhere to bind the value to, or you can't use the checkbox anyways, so a checkbox is appropriate. You'll need a wrapper class which can initialize the checkbox on load. Something like this:
The engagementList would be a List<EngagementWrapper>. Initialize this in your constructor or some function that loads a page worth of records at once (your choice), and create new instances of the EngagementWrapper for each row, adding it to the list. Remember to include Potential__r in your subquery so you don't get an error.
All Answers
Try creating a roll up summary field (COuntPotentail__c) on engagement object with have count of child records. then you can use the same to check/uncheck your checkbox on the VF Page
You need somewhere to bind the value to, or you can't use the checkbox anyways, so a checkbox is appropriate. You'll need a wrapper class which can initialize the checkbox on load. Something like this:
The engagementList would be a List<EngagementWrapper>. Initialize this in your constructor or some function that loads a page worth of records at once (your choice), and create new instances of the EngagementWrapper for each row, adding it to the list. Remember to include Potential__r in your subquery so you don't get an error.
Both replies are correct and can be used. However I used the implementation provided by sfdcfox. Thanks guys.