+ Start a Discussion
AndyPandyAndyPandy 

Can checkboxes appear as "Yes" or "No" rather than "true" or "false" on a VF Page?

Hi All,

 

I have (with a great deal of help from this forum) managed to put together a VF Page which renders a custom object record as a PDF - excellent start.

 

All the PDF displays, is a pretty basic form of all the fields from the record - so we can then email the PDF to people.

 

Some of these custom object fields, however, are Checkboxes, and on my PDFs the values for said Checkboxes display as "true" or "false" depending on what was input - which I completely agree makes sense.

 

However, the people I am making this PDF form for do not think all lower-case "true" or "false" look very pretty - so have requested that I amend this to read "Yes" for true and "No" for false.

 

At the moment, the only way I can think of doing this is to create a custom object formula field for each Checkbox I have, which is an IF statement to display either "Yes" or "No" - but with a LOT of checkboxes on the form this would be incredibly time consuming - and I would have thought there must be some form of VisualForce jiggery-pokery which could change the appearance of checkbox values on the VF Page - can anyone help?

 

Quick snippet of the code for the page as follows:

 

<apex:page renderAs="pdf" StandardController="Adverse_Incident__c" showHeader="false">

<html>

<head>
<style>
@page{
margin:0.25in;
}
.Label{
font-weight:bold;
font-size:10px;
font-family:"arial" "sans-serif";
}
.Output{
font-weight:regular;
font-size:10px;
font-family:Arial Unicode MS;
}
.colStyle{
width:25%;
}
</style>
</head>

<apex:outputText style="font-style:bold; font-weight:bold; font-size:14px; font-family:sans-serif" value="Incident Information"/>

   <apex:PanelGrid columnClasses="colStyle" columns="4" border="1" frame="box" rules="all" width="100%" cellpadding="1px">
<apex:outputlabel styleClass="Label" value="Person Reporting Incident"/>
<apex:outputText styleClass="Output" value="{!Adverse_Incident__c.Person_Reporting_Incident__c}"/>
<apex:outputlabel styleClass="Label" value="Incident ID"/>
<apex:outputText styleClass="Output" value="{!Adverse_Incident__c.Name}"/>
   </apex:PanelGrid>

<apex:outputText style="font-style:bold; font-weight:bold; font-size:2px; font-family:sans-serif; color:white" value="."/> <p></p>
<apex:outputText style="font-style:bold; font-weight:bold; font-size:14px; font-family:sans-serif" value="Facility Information"/> 
   
   <apex:PanelGrid columnClasses="colStyle" columns="4" border="1" frame="box" width="100%" cellpadding="1px">
<apex:outputlabel styleClass="Label" value="Hospital Name"/>
<apex:outputText styleClass="Output" value="{!Adverse_Incident__c.Hospital_Name__c}"/>
<apex:outputlabel styleClass="Label" value="Street Address"/>
<apex:outputText styleClass="Output" value="{!Adverse_Incident__c.Street_Address__c}"/>
<apex:outputlabel styleClass="Label" value="Account Number"/>

 

Any help would be greatly appreciated.  Many thanks,

 

Andy

Best Answer chosen by Admin (Salesforce Developers) 
Jake GmerekJake Gmerek

Hello,

 

I do not see any fields in your snippet that lend themselves to check boxes, so i will not go into specifics, but in general you should be able to do something along the lines of:

 

<apex:outputText value = "{!IF(my_checkbox_field__c, Yes, No)} />

 

I have not tested it, so you may have to add =true in there, but I would think not.

All Answers

Jake GmerekJake Gmerek

Hello,

 

I do not see any fields in your snippet that lend themselves to check boxes, so i will not go into specifics, but in general you should be able to do something along the lines of:

 

<apex:outputText value = "{!IF(my_checkbox_field__c, Yes, No)} />

 

I have not tested it, so you may have to add =true in there, but I would think not.

This was selected as the best answer
bob_buzzardbob_buzzard

The way I'd approach this is to create a custom component that takes a Boolean attribute and outputs YES or NO depending on the checkbox value.  Then you can replace your outputfields with that.

 

Something like the following - save the component as CheckboxTransform:

 

<apex:component>
   <apex:attribute name="cb" type="Boolean" description="Checkbox value"/>
   <apex:outputText value="Yes" rendered="{!cb}"/>
   <apex:outputText value="No" rendered="{!NOT(cb)}"/>
</apex:component>

 and you could call this with a field as follows:

 

<c:CheckboxTransform cb="{!MyObject__c.Checkbox_Field__c}"/>

 

The advantage to doing this is that if you need to change the text to Okay/No (for example) you only have one piece of code to hit.

AndyPandyAndyPandy

Hi Jake,

 

Thank you very much indeed for this - that's great.

 

Yes, I noticed after I posted my inital message that none of my included fields were Checkbox fields - my apologies.

 

But testing your method on actual checkbox fields in my page has worked perfectly - that's great!

 

Thank you as well bob for your reply - sadly I'm not quite advanced enough to pull of something as flash as that - but it's definitely something for me to look into to get better at this.

 

Cheers both,

 

Andy

Molly BolligMolly Bollig
On VisualForce Email Template:
To Show Checkboxes instead of True/False within the VF Code :
User-added image
<messaging:emailTemplate
  subject="example VF email template"
  recipientType="User"
  relatedToType="Opportunity"
>
  <messaging:htmlEmailBody>
    <html>
      <body>
        <apex:repeat var="o" value="{!relatedTo}">
          <table>
            <tr>
              <td>Client Request 1</td>
              <td>{!IF(!o.client_request_1__c, '☐','☑︎')}</td>
            </tr>

            <tr>
              <td>Client Request 2</td>
              <td>{!IF(!o.client_request_2__c, '☐','☑︎')}</td>
            </tr>
          </table>
        </apex:repeat>
      </body>
    </html>
  </messaging:htmlEmailBody>
</messaging:emailTemplate>

 
Naomy QuinonesNaomy Quinones
I'm using Jake's answer, but be mindful of adding the quotation marks. 

<apex:outputText value = "{!IF(my_checkbox_field__c, "Yes", "No")} />

Thank you so much !!!