function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prashant BhattPrashant Bhatt 

Hi, I am new to salesforce. I am using salesforce sites to create a webform . I have a field where u can select multiple checkboxes , if u select 'OTHER' it should generrate a inputfield

This is my visualforce code. Please help!

<apex:pageBlockSection title="RMS SYSTEM" columns="1" collapsible="false" id="thePbs2"  >
            <apex:outputLabel value="{!$ObjectType.Datavis_Client__c.Fields.RMS_SYSTEM__c.InlineHelpText}" />
           <apex:selectcheckboxes layout="pageDirection"  value="{!MPItems}" label="" id="checkbox1">  
               
               <apex:selectoptions value="{!MPOptions}" > 
                  
               <apex:actionSupport event="onselect" reRender="ajaxrequest" />
                </apex:selectoptions>       
            </apex:selectcheckboxes>
                
              <apex:outputPanel id="ajaxrequest">
                   <apex:outputPanel rendered=" {!MPOptions=='OTHER'}" >
                    <apex:inputField value="{!Datavis_Client__c.Others_data__c}" />
                     </apex:outputPanel>

                   </apex:outputPanel>
           
         </apex:pageBlockSection>
Best Answer chosen by Prashant Bhatt
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Prashant, 

Why do you have 2 output panels - 
<apex:outputPanel id="ajaxrequest">
     <apex:outputPanel  rendered="{!isRendered}" >
      <apex:inputField value="{!Datavis_Client__c.Others_data__c}" />
      </apex:outputPanel>
</apex:outputPanel>
You can merge into one - 
Try this instead -
<apex:outputPanel id="ajaxrequest" rendered="{!isRendered}">
       <apex:inputText value="{!Datavis_Client__c.Others_data__c}"  />
 </apex:outputPanel>
In the controller - 
public PageReference  showOrHideInputBox() {        
	Set<String> strSet = new Set<String>(MPItems);
    isRendered = (strSet.contains('OTHERS')) ? true : false;    
}
Let me know, if it helps you


Thanks,
Sumit Kumar Singh

 

All Answers

Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Prashant,
I can't see any action attribute in Action support.
<apex:actionSupport event="onclick" action="{!showOrHideCheckbox}" reRender="ajaxrequest"/>
In the controller -
//You can define a boolean variable - 
public boolean isRendered{get;set;}
//Assign default value in the constructor, 'reportController' is the name of constructor
public reportController(){
   isRendered = false;
} 
public void showOrHideCheckbox() {
     isRendered = (MPOptions=='OTHER') ? true : false;    
}
Update the output panel like this -
<apex:outputPanel id="ajaxrequest" rendered="{!isRendered}">
<apex:inputField value="{!Datavis_Client__c.Others_data__c}" />
</apex:outputPanel>
Hope, this will help you.


Thanks, 
Sumit Kumar Singh

 
Prashant BhattPrashant Bhatt
Hi Sumit, Thanks for replying!!..  I have added controller action as u sugested,and input field is coming but if rendered is false then also it is coming .Debugging isRendered is correctly displaying.Please suggest me what am i m doiing wrong.
My controller code-
 public PageReference  showOrHideInputBox() {
         
          List<SelectOption> rmsOption = this.MPOptions;
          for(SelectOption s : rmsOption) {
             isRendered = (s.getValue()=='OTHER') ? true : false; 
               system.debug(isRendered);
            }
          return null;
       }
Visualforce code-
<apex:pageBlockSection title="RMS SYSTEM" columns="1" collapsible="false" id="thePbs2"  >
            <apex:outputLabel value="{!$ObjectType.Datavis_Client__c.Fields.RMS_SYSTEM__c.InlineHelpText}" />
           <apex:selectcheckboxes layout="pageDirection"  value="{!MPItems}"  id="checkbox1">  
               <apex:selectoptions value="{!MPOptions}" > 
                </apex:selectoptions>
                <apex:actionSupport event="onclick"  action="{!showOrHideInputBox}" reRender="ajaxrequest"/>
               </apex:selectcheckboxes>
               
                   <apex:outputPanel id="ajaxrequest">
                       <apex:outputPanel  rendered="{!isRendered}" >
                        <apex:inputField value="{!Datavis_Client__c.Others_data__c}" />
                       </apex:outputPanel>
                    </apex:outputPanel>
             
           
         </apex:pageBlockSection>  
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Prashant, 

Why do you have 2 output panels - 
<apex:outputPanel id="ajaxrequest">
     <apex:outputPanel  rendered="{!isRendered}" >
      <apex:inputField value="{!Datavis_Client__c.Others_data__c}" />
      </apex:outputPanel>
</apex:outputPanel>
You can merge into one - 
Try this instead -
<apex:outputPanel id="ajaxrequest" rendered="{!isRendered}">
       <apex:inputText value="{!Datavis_Client__c.Others_data__c}"  />
 </apex:outputPanel>
In the controller - 
public PageReference  showOrHideInputBox() {        
	Set<String> strSet = new Set<String>(MPItems);
    isRendered = (strSet.contains('OTHERS')) ? true : false;    
}
Let me know, if it helps you


Thanks,
Sumit Kumar Singh

 
This was selected as the best answer
Prashant BhattPrashant Bhatt
Thanks alot Sumit!!..  that really helps!!. Please can you tell me one more thing . I have a validation on onsubmit of form too. when i am removing validationh then only  ajax  is working . Otherwie it is getting validation errors. 
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Prashant, 
You can use <apex:actionRegion> to over come this - 
Have a look at this - 
http://www.tgerm.com/2010/09/visualforce-actionregion-deep-dive.html
Prashant BhattPrashant Bhatt
Hi Sumit . Sorry for Disturb you again!.  I have checked with url and try to implement <apex:actionRegion>  its not working for me.

<apex:pageBlockSection title="RMS SYSTEM" columns="1" collapsible="false" id="thePbs2"  >
            <apex:outputLabel value="{!$ObjectType.Datavis_Client__c.Fields.RMS_SYSTEM__c.InlineHelpText}" />
              <apex:actionRegion>
           <apex:selectcheckboxes layout="pageDirection"  value="{!MPItems}"  id="checkbox1">  
                 <apex:selectoptions value="{!MPOptions}" > 
                </apex:selectoptions>
                <apex:actionSupport event="onclick"  action="{!showOrHideInputBox}" reRender="ajaxrequest"/>
                </apex:selectcheckboxes>
                 </apex:actionRegion>
                <apex:outputPanel id="ajaxrequest">
                <apex:outputPanel  rendered="{!isRendered}" >
                        <apex:inputField value="{!Datavis_Client__c.Others_data__c}" />
                       </apex:outputPanel>
                
                </apex:outputPanel>
               </apex:pageBlockSection>

 if i am putting  apexRegion inside  <Apex:selectcheckboxes> it is throwing error that  select box should have one child .and outside  its same as without apexRegion.    Please help!
Sumit Kumar Singh 9Sumit Kumar Singh 9
You can also try "immediate=true" it iwll skip the valdation rules.