Hi All
I had come across in a requirement,the Requirement was to select one record and disable all the records after selecting in that table. I have done it by using JavaScript, I think it will help you.
This is the page.
<apex:page>
<apex:form>
<script>
function checkboxuse(tag) {
var menus = document.getElementsByClassName("Teststyle");
if (tag.checked == true) {
for (var i = menus.length - 1; i >= 0; i--)
{
menus[i].disabled = true;
}
tag.disabled = false;
}
else {
for (var i = menus.length - 1; i >= 0; i--)
{
menus[i].disabled = false;
}
}
}
</script>
<apex:PageBlock>
<apex:pageBlockTable value = "{!listofRecords}" var = "c" >
<apex:column header = "Select" >
<apex:inputCheckBox value = "{!c.selected}" id="tst" styleClass="Teststyle" onchange="return checkboxuse(this)"/>
</apex:column>
<apex:column header = "FieldName">
<apex:inputFiled value = "{!c.filedAPIName}" />
</apex:column>
</apex:pageBlockTable>
</apex:PageBlock>
</apex:form>
</apex:page>
You have to use wrapper class, listofRecords should be a wrapper class List.
I had come across in a requirement,the Requirement was to select one record and disable all the records after selecting in that table. I have done it by using JavaScript, I think it will help you.
This is the page.
<apex:page>
<apex:form>
<script>
function checkboxuse(tag) {
var menus = document.getElementsByClassName("Teststyle");
if (tag.checked == true) {
for (var i = menus.length - 1; i >= 0; i--)
{
menus[i].disabled = true;
}
tag.disabled = false;
}
else {
for (var i = menus.length - 1; i >= 0; i--)
{
menus[i].disabled = false;
}
}
}
</script>
<apex:PageBlock>
<apex:pageBlockTable value = "{!listofRecords}" var = "c" >
<apex:column header = "Select" >
<apex:inputCheckBox value = "{!c.selected}" id="tst" styleClass="Teststyle" onchange="return checkboxuse(this)"/>
</apex:column>
<apex:column header = "FieldName">
<apex:inputFiled value = "{!c.filedAPIName}" />
</apex:column>
</apex:pageBlockTable>
</apex:PageBlock>
</apex:form>
</apex:page>
You have to use wrapper class, listofRecords should be a wrapper class List.
Comments
Good post. I have a requirement where i have to check a checkbox based on condition.
E.g I have 3 objects contact,application and verifier. Verifier is junction object b/w contact and application. In vf page i have a pagebocktable with 2 columns. 1st column has all contacts and 2 column is for verifier and has checkboxes. If a contact is verifier then checkbox should be checked.
listofRecords should list of records of one object.
I have requirement related to the checkbox is disabled whenever input field value is zero
I have one wrapper list, in this wrapper having one checkbox and one input field
I am trying two way but not working properly
Apex code
//============================================
public boolean checkBoxDisabled {get;set;}
Public void quantityZero(){
for(Integer i = 0; i < wrapList.size();i++){
if(Decimal.valueOf(wrapList[i].azure.Quantity__c) <= 0){
checkBoxDisabled = true;
}
}
}
//===============================================