3

I have a inline VF page where i show child records of the object. The child records are rendered in a apex:pageblock table. I am using apex:inlineeditsupport to enable inline editing of the fields for the child records. I have two buttons - Save and Cancel.

Save - Should save the record that was edited using inlineedit

Cancel - Should simply reset everything on the page

Below is the code snippet:

<apex:page standardController="MyCustomParentObject__c" extensions="MyInlineEditExt" id="thePage" docType="html-5.0">

<apex:form id="theForm" >   
      <apex:pageBlock id="thepageblock" mode="inlineEdit">
         <apex:pageMessages /> 
           <apex:pageBlockButtons id="thePageBlockButtons">
                <apex:commandButton action="{!saveDetailRecs}" immediate="true" id="saveButton" value="Save" style="display:none;"/>
                <apex:commandButton onclick="resetInlineEdit()" html-formnovalidate="novalidate" immediate="true" id="cancelButton" value="Cancel" style="display:none;"/>
            </apex:pageBlockButtons>

           <apex:pageBlockTable value="{!lstDetailRecs}" var="item" width="100%" id="thetable">
             <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Ownership ID" action="{!getDetailRecs}" reRender="none">
                            <apex:param value="Ownership_ID__c" name="sortCriteria"/>                           
                        </apex:commandLink>
                    </apex:facet>                   
                <apex:outputField value="{!item.Ownership_ID__c}">
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                        hideOnEdit="nextLink, beginningLink, previousLink, endLink" event="ondblclick" 
                        changedStyleClass="myBoldClass" />
                </apex:outputField> 
              </apex:column>

              <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Pay Rate" action="{!getDetailRecs}" reRender="thepageblock">
                            <apex:param value="Pay_Rate__c" name="sortCriteria"/>                           
                        </apex:commandLink>
                    </apex:facet> 

                      <apex:outputField value="{!item.Pay_Rate__c}">
                            <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                                hideOnEdit="nextLink, beginningLink, previousLink, endLink" event="ondblclick" 
                                changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                      </apex:outputField>   
              </apex:column>

              <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Date From" action="{!getDetailRecs}" reRender="thepageblock">
                            <apex:param value="Date_From__c" name="sortCriteria"/>                              
                        </apex:commandLink>
                    </apex:facet>

                <apex:outputField value="{!item.Date_From__c}">             
                    <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                        hideOnEdit="nextLink, beginningLink, previousLink, endLink" event="ondblclick" 
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
              </apex:column>
              <apex:column headerValue="Date Through">
                    <apex:facet name="header">
                        <apex:commandLink value="Date Through" action="{!getDetailRecs}" reRender="thepageblock">
                            <apex:param value="Date_Through__c" name="sortCriteria"/>                           
                        </apex:commandLink>
                    </apex:facet>      
                    <apex:outputField value="{!item.Date_Through__c}">              
                        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                            hideOnEdit="nextLink, beginningLink, previousLink, endLink" event="ondblclick" 
                            changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                </apex:outputField>
           </apex:pageBlockTable>          
      </apex:pageBlock>
 </apex:form>     
</apex:page>

The problem is that when i do inline edit and click Cancel, instead of resetting the fields, validations are fired and the page is refreshed throwing an error. What i want is when user clicks Cancel, no validations fire and the values are reset similar to what we get when user clicks on undo.

enter image description here

I have tried below possible options -

  1. Set immediate="true" for the commandbutton
  2. Set html-formnovalidate = "novalidate"
  3. Calling action method from the class and return Current pagereference
  4. Calling java script and reload the page.

None of the above approach is working. I am not sure what can be done to overcome this issue.

  • 1
    It looks like it's not cancel that fails, but resetFunction? – Adrian Larson Aug 1 '16 at 13:38
  • Thanks @AdrianLarson. I changed the onclick="resetInlineEdit();" to this.form.reset(); and it worked fine. – Shailesh Deshpande Aug 2 '16 at 8:30
0

I was able to resolve this by using onclick="this.form.reset();"

<apex:commandButton onclick="this.form.reset();" id="cancelButton" value="Cancel" style="display:none;"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.