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
Jeff_SFJeff_SF 

Set default value for text feild in VF page

How can a default value be set in a VF page in a long text feild? Currently the default value set in the object feild for comments__c does not populate when the record is entered from the VF page.
 </apex:tab>
                <apex:tab label="Comments" name="CommentsTab" id="tabComments">
                    <apex:pageBlockSection columns="1" id="CommentsPageBlock">
                        <apex:outputField value="{!Inspection__c.Comments__c}" id="Comments" />
                    </apex:pageBlockSection>
                </apex:tab>
 
Best Answer chosen by Jeff_SF
pconpcon
In the code you have above, you are using inputTextArea.  You should be using inputField if you want the default value to be presented.  For example
 
<apex:tab label="Comments" name="CommentsTab" id="tabcomments">
    <apex:pageBlockSection columns="1" id="CommentsPageBlock">
        <apex:inputField value="{!Inspection__c.Comments__c}" id="Comments"/>
    </apex:pageBlockSection>
</apex:tab>

If you need to use inputTextArea then you will need to pre-populate the value of Comments__c in your controller with the default value.  You can pull this using the describe methods.

All Answers

pconpcon
In your code above, you have outputField when I use inputField I see the expected default value of the field populated.  Do you mean to have outputField?

NOTE: When adding code, please use the "Add a code sample" button (icon <>)
Jeff_SFJeff_SF
</apex:tab>
                
                <apex:tab label="Comments" name="CommentsTab" id="tabcomments">
                    <apex:pageBlockSection columns="1" id="CommentsPageBlock">
                            <apex:inputTextarea cols="200" rows="15" value="{!Inspection__c.Comments__c}" id="Comments"/>
                    </apex:pageBlockSection>
                </apex:tab>

Yes thenk you, InputFeild, above is the code sample.  When a new record is entered from the VF form, the default value set for the feild does not populate the feild in the form. Does the default value need to be included in the code? 
pconpcon
In the code you have above, you are using inputTextArea.  You should be using inputField if you want the default value to be presented.  For example
 
<apex:tab label="Comments" name="CommentsTab" id="tabcomments">
    <apex:pageBlockSection columns="1" id="CommentsPageBlock">
        <apex:inputField value="{!Inspection__c.Comments__c}" id="Comments"/>
    </apex:pageBlockSection>
</apex:tab>

If you need to use inputTextArea then you will need to pre-populate the value of Comments__c in your controller with the default value.  You can pull this using the describe methods.
This was selected as the best answer
Jeff_SFJeff_SF
I need a larger area for inputting the data than is available for the standard inputFeild.  Is there a way to resize this input feild in the VF form?  If not I would need more information on where to find the controller since I am a newbee...
pconpcon
You can modify the style of the inputField and set the height and width to what you need
 
<apex:inputField style="width: 300px; height: 300px;" value="{!Inspection__c.Comments__c}" id="Comments" />
Jeff_SFJeff_SF
that code worked great to expand the area but the default value for field is no longer populating in a new record.  Also I am getting an error when tryin to save the record:
Error:j_id0:inspect:detail:CSPageBlock:j_id34:CS: Validation Error: Value is required.
It is pointing to this line. 
<apex:inputField value="{!Inspection__c.Customer__c}" id="customer" required="true" />
This required customer value is in the form when trying to save...
 
pconpcon
Are you using a custom controller on this page or a Standard controller?  Are you using the standard save action or a custom action?
Jeff_SFJeff_SF
save action:
<apex:pageBlockButtons location="both">
                <apex:commandButton action="{!save}" value="Save" />
                <apex:commandButton action="{!cancel}" value="Cancel" />
            </apex:pageBlockButtons>

controller:
<apex:page standardController="Inspection__c" showHeader="true">


 
pconpcon
I have almost the exact same VF page and it works fine for me.  What version of the API are you running?  And you are 100% certian that there are no other required fields that Salesforce could be confusing and not saving the record because of?  Can you provide your entire visualforce page?
 
<apex:page standardController="Student__c">
    <apex:form >
        <apex:inputField style="width: 300px; height: 300px;" value="{!Student__c.long_text__c}" required="true"/>
        <apex:commandButton action="{!save}" value="Save" />
    </apex:form>
</apex:page>

 
Jeff_SFJeff_SF
I did find a missing required feild and no longer getting the error. 

When a new record is created the field in question is blank.It does populate when the record is saved only if no value is entered in the blank field  when a new record is created.  The purpose of the default text is to guide/instruct the user what info to enter - it is rather lengthy.  In order to get the proper instruction, the user must leave the field blank when creating a new record and then go back into edit mode to get the intructions (populated with the default text). Any suggestions on how to get around this?  the same form is being used for NEW and EDIT actions. Am using version 18.0 API.  The VF page would not post - had too many lines to post. 

 
Jeff_SFJeff_SF
I created another form for entering data without the comments fieild.  Once record is saved the field populates.  It can be edited using a different form that includes the comments field.   It is a two step process for data entry, not pretty but it is working. Thanks for the help.