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
RoopaRoopa 

Problem with OnLoad and checking Text value validation

Hi,
whenever value="{!test.Bu__c}" in OutputText doesn't have value , I should display "NONE" , So that I've wriiten function ,but it's not displaying NONE when it doesn't have value.It's displaying blank value.
 
Help on this!
 
Code:
<apex:page standardController="Test__c" extensions="extenfun" renderAs="pdf" >
   <apex:detail subject="{!Test__c}" relatedList="false"/>
   <apex:repeat value="{!Test___c.testing__r}" var="test">
   <apex:form >
          <apex:pageBlock title="Try">
              <apex:pageBlockSection title="List" >
              <apex:outputLabel  value="Bu Level"  />
                  <apex:outputText  id="BUnew" value="{!test.Bu__c}"/>
          
            </apex:pageBlockSection>
                                      
          </apex:pageBlock>
          <script>
          window.onload=function setBU(){
           var arr=document.getElementById ('{!$Component.Bu__c}').value;
             if(arr==null)
           document.getElementById ('{!$Component.Bu__c}').value="--none--";
             else
             document.getElementById ('{!$Component.Bu__c}').value="{!test.Bu__c}";
    
          }
          </script>
       </apex:form>
   </apex:repeat>
 </apex:page>
dchasmandchasman
Roopa,

You are making things way too complicated in your attempted solution and there is at least one thing that is just are not going to work once you throw in renderAs="pdf". Rendering to pdf happens entirely on our servers where javascript is not going to be evaluated (BTW your approach to hooking window.onload is very very dangerous because lots of things in sfdc (and most web applications in general) require their own code to run during onload - there is a safe way to do what you want using javascript closures).

The solution is very simple once you leverage page formulas:

Code:
<apex:outputText id="BUnew" value="{!nullValue(test.name, '---none---')}"/>

 Also it is a very bad idea and totally unnecessary to nest <apex:form>'s inside a repeat. The final solution will look something like this:

Code:
<apex:page standardController="Test__c" extensions="extenfun" renderAs="pdf" >
<apex:detail subject="{!Test__c}" relatedList="false"/>
<apex:repeat value="{!Test___c.testing__r}" var="test">
<apex:pageBlock title="Try">
<apex:pageBlockSection title="List" >
<apex:outputLabel value="Bu Level" />
<apex:outputText id="BUnew" value="{!nullValue(test.name, '---none---')}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:repeat>
</apex:page>

 

RoopaRoopa
Thanks for your solution.Thanks a lot Doug Chasman!!!!