1

I have a requirement where I need to assign the value entered in apex:inlineeditsupport to a variable on the page everytime that inlineedit support tag is double clicked and edited. Is it possible to assign it to an apex:variable? Can anyone give me a simplified example as to how it can be done.

Actually I want to capture the value of the field after inlinedit has been done an before it has been saved in the database. Depending on that a alert is to be displayed

1 Answer 1

0

Just use inlineEdit support with apex:outputField..

<apex:outputField value="{!customerObj.Address__c}">
      <apex:inlineEditSupport showOnEdit="saveButton" event="ondblclick"/>    
</apex:outputField>

TO get the inline Edit value use like this.

Wrap your inline Edit inside a div and give a class name

<div Class="tdData">
   <apex:pageBlockSection >
       <apex:outputField value="{!contact.lastname}">
            <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                            hideOnEdit="editButton" event="ondblclick" 
                            changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
       </apex:outputField>

    <apex:outputField value="{!contact.accountId}"/>
    <apex:outputField value="{!contact.phone}"/>
  </apex:pageBlockSection>
</div>

And srcipt

<apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"/>
        <script>
          $(document).ready(function() {
              $('.tdData :hidden').change(function(e) {
                 alert(e.target.value);
            });
          });
        </script>

Now when inside tdData class inside hidden value updated this script will execute and we can check the value in alert.

Complete code.. I have tested below code.

<apex:page standardController="Contact">
    <apex:form >
        <apex:pageBlock>
            <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>

            <div Class="tdData">
                <apex:pageBlockSection >
                    <apex:outputField value="{!contact.lastname}">
                        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                            hideOnEdit="editButton" event="ondblclick" 
                            changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                    </apex:outputField>

                    <apex:outputField value="{!contact.accountId}"/>
                    <apex:outputField value="{!contact.phone}"/>
                </apex:pageBlockSection>
            </div>
        </apex:pageBlock>
        <apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"/>
        <script>
          $(document).ready(function() {
              $('.tdData :hidden').change(function(e) {
                 alert(e.target.value);
            });
          });
        </script>
    </apex:form>
</apex:page>
9
  • Actually I want to capture the value of the field after inlinedit has been done an before it has been saven in the database. Depending on that a alert is to be displayed. @Ratan
    – Rimii
    Commented Jan 27, 2016 at 5:13
  • @Rimii I don't this you can do that.. You can check the value using javscript or in controller side.. How you are saving the data in database.. using any DML in controller side? if yes then check value in controller
    – Ratan Paul
    Commented Jan 27, 2016 at 5:17
  • @Rimii can't we check the value in controller side ?
    – Ratan Paul
    Commented Jan 27, 2016 at 5:39
  • We can't. My requirement is that if that particular field has been entered a null value, an alert is to be displayed. The alert is displayed on savebutton click depending on whether a null value has been entered. It will display the alert but would not save the null value
    – Rimii
    Commented Jan 27, 2016 at 5:42
  • @Rimii check my updated ans.. You can use jquery to bind the change event whenever inline support change the value javascript function will be called there we can check the value.. I suggest try to create new page then check my complete code how that works. and it will work for you or not..
    – Ratan Paul
    Commented Jan 27, 2016 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .