+ Start a Discussion
Kristen Aldrich 14Kristen Aldrich 14 

If field in Visualforce pageBlockTable is empty, I can't edit it to add data.

I'm creating a Visualforce pageBlockTable for some custom fields on an Opportunity record. It works great when data is entered upon creation of an Opportunity record, but any blank fields in the pageBlockTable are inaccessible so I can't create the opportunity and go back to add data into those fields. How can I make blank fields editable in the table?
 
<apex:page standardController="Opportunity">
    <apex:form >
        <apex:pageBlock mode="inlineEdit">
             <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
                <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
                <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
                </apex:pageBlockButtons>
            <apex:pageBlocktable value="{!Opportunity.Meal_Date_1__c}" var="Meal_Date_1__c">
                  <apex:column headerValue="Day 1">
                    <apex:inputfield value="{!Opportunity.Meal_Date_1__c}"/>
                    <apex:outputField value="{!Opportunity.Meal_Date_1__c}"/>
                </apex:column>
                <apex:column headerValue="Breakfast">    
                    <apex:inputField value="{!Opportunity.Breakfast_1__c}" />
                </apex:column>
                <apex:column headerValue="Lunch">
                    <apex:inputField value="{!Opportunity.Lunch_1__c}" />
                </apex:column>
                <apex:column headerValue="Dinner">
                    <apex:inputField value="{!Opportunity.Dinner_1__c}" />
                </apex:column>
                <apex:column headerValue="Time">
                    <apex:inputField value="{!Opportunity.Meal_Time_1__c}" />
                </apex:column>
                </apex:pageBlockTable>
                <apex:pageBlockTable value="{!Opportunity.Meal_Date_2__c}" var="Meal_Date_2__c">
                <apex:column headerValue="Day 2">
                    <apex:inputField value="{!Opportunity.Meal_Date_2__c}" />
                </apex:column>
                <apex:column headerValue="Breakfast">    
                    <apex:inputField value="{!Opportunity.Breakfast_2__c}" />
                </apex:column>
                <apex:column headerValue="Lunch">
                    <apex:inputField value="{!Opportunity.Lunch_2__c}" />
                </apex:column>
                <apex:column headerValue="Dinner">
                    <apex:inputField value="{!Opportunity.Dinner_2__c}" />
                </apex:column>
                <apex:column headerValue="Time">
                    <apex:inputField value="{!Opportunity.Meal_Time_2__c}" />
                </apex:column>
                <apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
                </apex:pageBlockTable>
                <apex:pageBlockTable value="{!Opportunity.Meal_Date_3__c}" var="Meal_Date_3__c">
                <apex:column headerValue="Day 3">
                    <apex:inputField value="{!Opportunity.Meal_Date_3__c}" />
                </apex:column>
                <apex:column headerValue="Breakfast">    
                    <apex:inputField value="{!Opportunity.Breakfast_3__c}" />
                </apex:column>
                <apex:column headerValue="Lunch">
                    <apex:inputField value="{!Opportunity.Lunch_3__c}" />
                </apex:column>
                <apex:column headerValue="Dinner">
                    <apex:inputField value="{!Opportunity.Dinner_3__c}" />
                </apex:column>
                <apex:column headerValue="Time">
                    <apex:inputField value="{!Opportunity.Meal_Time_3__c}" />
                </apex:column>
                <apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
                </apex:pageBlockTable>
                <apex:pageBlockTable value="{!Opportunity.Meal_Date_4__c}" var="Meal_Date_4__c">
                <apex:column headerValue="Day 4">
                    <apex:inputField value="{!Opportunity.Meal_Date_4__c}" />
                </apex:column>
                <apex:column headerValue="Breakfast">    
                    <apex:inputField value="{!Opportunity.Breakfast_4__c}" />
                </apex:column>
                <apex:column headerValue="Lunch">
                    <apex:inputField value="{!Opportunity.Lunch_4__c}" />
                </apex:column>
                <apex:column headerValue="Dinner">
                    <apex:inputField value="{!Opportunity.Dinner_4__c}" />
                </apex:column>
                <apex:column headerValue="Time">
                    <apex:inputField value="{!Opportunity.Meal_Time_4__c}" />
                </apex:column>
                <apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
                </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Best Answer chosen by Kristen Aldrich 14
Kristen Aldrich 14Kristen Aldrich 14
I was able to utilize apex:pageBlockSection to achieve what I needed. Thanks!

All Answers

Alain CabonAlain Cabon
Hi,

We never use <apex:pageBlocktable> with unique values and that is your problem.
This trick was used to prevent the display of empty field probably but that also prevents the input of their values for inline editing. 

<apex:pageBlocktable value="{!Opportunity.Meal_Date_1__c}" var="Meal_Date_1__c">
<apex:pageBlockTable value="{!Opportunity.Meal_Date_2__c}"var="Meal_Date_2__c">

<apex:pageBlockTable value="{!Opportunity.Meal_Date_3__c}" var="Meal_Date_3__c"> 
<apex:pageBlockTable value="{!Opportunity.Meal_Date_4__c}"var="Meal_Date_4__c">


If you want a table format with unique values, you can just use the HTML and CSS tags.

https://www.lightningdesignsystem.com/components/data-tables/
 
Kristen Aldrich 14Kristen Aldrich 14
Thank you Alain. I am new to visualforce page development and quickly got lost with the link you provided. Is that a lightning component? Would I enter that code as a new Visualforce page? Is this the only solution? 
Kristen Aldrich 14Kristen Aldrich 14
I was able to utilize apex:pageBlockSection to achieve what I needed. Thanks!
This was selected as the best answer