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
impalacrazy69impalacrazy69 

copy input field data into another input field

So i found a similar message here hat gave some insight into how to copy text from my venue address fields to my vendor address fields. The code shown was just JS and im using apex so getting i to work has my brain spinning. So atached is my controller code and the vf code. I have tried actionsupport functions, onlick, action region and rendered but notihng seems to pass any data. I took the rendered out becasue it gave me a save error about type not matching.


Can anyone see what im going wrong:

My Controller code:

public PageReference getsameAddress (){ 
       	if (this.request.Same_as_Venue__c == true)
       	{
       		this.request.Venue_Address__c = this.request.Company_Address__c;
       		this.request.Venue_City__c = this.request.Company_City__c;
       		this.request.Venue_Postal__c = this.request.Company_Postal__c;
       		this.request.Venue_Country__c = this.request.Company_Country__c;
       		this.request.Venue_State__c = this.request.Company_State__c;
       	}	
      return null;
    } 

 

My vf code:

 <!-- Vendor Info -->
    <!-- Only displayed for internal users -->
    <apex:pageBlockSection title="Vendor Details" rendered="{!isInternal}" columns="1" id="vendorinfo">
       <apex:pageBlockSectionItem >
         	<apex:actionregion >
            	<apex:outputLabel >Same as Venue Details</apex:outputLabel>
              <apex:inputField value="{!request.Same_as_Venue__c}">
            		<apex:actionSupport event="onclick" />
            	</apex:inputField>
            </apex:actionregion>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Phone</apex:outputLabel>
            <apex:inputField value="{!request.Company_Phone__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Address</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_Address__c}" styleClass="longinput"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >City</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_City__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Postal Code</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_Postal__c}"/>
        </apex:pageBlockSectionItem>
        
        <!-- 
        This is a little complex...
        The action region allows the page to only submit this specific field
        to the controller when calling AJAX functionality. Without the action region,
        required fields cause the rerender action to fail.
        -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Country</apex:outputLabel>
            <apex:actionRegion >
            <apex:inputField required="true" value="{!request.Company_Country__c}">
                <apex:actionSupport event="onchange" reRender="vendorstate"/>
            </apex:inputField>
            </apex:actionRegion>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    

 

liron169liron169
Hello,

I don't surely understand from which field to which you want to copy, but it can be done using javascript.
souvik9086souvik9086

Can you share more info about the req? Exactly which field to copy to where? 

 

Thanks

Avidev9Avidev9

You were so close man!

You missed the controller call from the action support

 

<apex:inputField value="{!request.Same_as_Venue__c}">
            		<apex:actionSupport event="onchange" action="{!getSameAddress}"/>
            	</apex:inputField>

 

 

impalacrazy69impalacrazy69

Thanks Avidev9, however now im getting the "must enter value" error on my req fields. Im wondering if i can have more than one actionregion tag in the text.

 

And the fields i am trying to push are:

 

Venue Address into Company Address field

Venue City into Company City

Venue Postal into Company Postal

Venue Country into Company Country (this is a picklist)

Venue State into Company State (this is a picklist)

 

Im doing this in the controller. Here is the vf code for both sections:

 

<!-- Venue Info -->
    <apex:outputPanel id="venuedetailspanel">
    <apex:pageBlockSection title="Venue Details" columns="1" id="venuedetails" rendered="{!checkMe}" >
        <apex:inputField required="true" value="{!request.Venue_Name__c}"  styleClass="normalinput"/>
        
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Address</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Venue_Address__c}" styleClass="longinput"/>
            
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >City</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Venue_City__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Postal Code</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Venue_Postal__c}"/>
        </apex:pageBlockSectionItem>
        
        <!-- Same actionRegion pattern as above -->
        <apex:pageBlockSectionItem dataStyleClass="requiredInput" >
            <apex:outputLabel >Country</apex:outputLabel>
            <apex:actionRegion >
            <div class="requiredInput">
            <div class="requiredBlock"></div>
            <apex:selectList value="{!request.Venue_Country2__c}" size="1">
                <apex:actionSupport event="onchange" reRender="venuestate"/>
                <apex:selectOptions value="{!CountryOptions}"/>
            </apex:selectList>
            </div>
            </apex:actionRegion>
       </apex:pageBlockSectionItem>
    </apex:pageBlockSection> 

    <apex:pageBlockSection columns="1" id="venuestate">
        <apex:pageBlockSectionItem rendered="{!venueRequiresState}">
            <apex:outputLabel >State/Province</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Venue_State__c}"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    </apex:outputPanel>
    <!-- END Venue Info -->


    <!-- Vendor Info -->
    <!-- Only displayed for internal users -->
    <apex:pageBlockSection title="Vendor Details" rendered="{!isInternal}" columns="1" id="vendorinfo">
        <!-- This field is commented out in case users request to have it put back -->
        <!--  apex:pageBlockSectionItem -->
            <!-- apex:outputLabel >Vendor Name</apex:outputLabel-->
            <!-- apex:outputField value="{!request.Company_Name__c}" /-->
        <!-- /apex:pageBlockSectionItem-->
         <apex:pageBlockSectionItem >
         	<apex:actionregion >
            	<apex:outputLabel >Same as Venue Details</apex:outputLabel>
              <apex:inputField value="{!request.Same_as_Venue__c}">
            		<apex:actionSupport event="onchange" action="{!getsameAddress}"/>
            	</apex:inputField>
            </apex:actionregion>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Phone</apex:outputLabel>
            <apex:inputField value="{!request.Company_Phone__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Address</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_Address__c}" styleClass="longinput"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >City</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_City__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Postal Code</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_Postal__c}"/>
        </apex:pageBlockSectionItem>
        
        <!-- 
        This is a little complex...
        The action region allows the page to only submit this specific field
        to the controller when calling AJAX functionality. Without the action region,
        required fields cause the rerender action to fail.
        -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Country</apex:outputLabel>
            <apex:actionRegion >
            <apex:inputField required="true" value="{!request.Company_Country__c}">
                <apex:actionSupport event="onchange" reRender="vendorstate"/>
            </apex:inputField>
            </apex:actionRegion>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    
    <!-- State is in its own section so we only need to rerender
         one field. Rerendering the entire venue section causes
         filled in fields to be cleared -->
    <apex:pageBlockSection columns="1" id="vendorstate">
        <apex:pageBlockSectionItem rendered="{!companyRequiresState}">
            <apex:outputLabel >State/Province</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_State__c}"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    <!-- END Vendor Info -->

 

Avidev9Avidev9

Just wrap the inputField with action Region 

 

    <apex:actionRegion>   
<apex:inputField value="{!request.Same_as_Venue__c}"> <apex:actionSupport event="onchange" action="{!getSameAddress}" rerender="pbs"/> </apex:inputField>
</apex:ActionRegion>
....

....

....

<apex:pageBlockSection id="pbs">
<apex:pageBlockSectionItem > <apex:outputLabel >Address</apex:outputLabel> <apex:inputField value="{!request.Venue_Address__c}" styleClass="longinput"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel >City</apex:outputLabel> <apex:inputField value="{!request.Venue_City__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel >Postal Code</apex:outputLabel> <apex:inputField value="{!request.Venue_Postal__c}"/> </apex:pageBlockSectionItem>
</apex:pageBlocSection>
 
impalacrazy69impalacrazy69

Still getting the "must enter value" error message. Plus i dont see any data being pushed into the fields

Avidev9Avidev9
edited the answer
impalacrazy69impalacrazy69

So it looks like your update has me creating a new pageblocksection just around the fields i am pushing data into is that correct.

 

Meaning:

1. Same as venue checkbox should be its own pageblocksection

2. Address / City / State / etc should have their own page block section

 

See mocked code attached.

 

   <apex:pageBlockSection title="Vendor Details" rendered="{!isInternal}" columns="1" id="vendorinfo">
        <!-- This field is commented out in case users request to have it put back -->
        <!--  apex:pageBlockSectionItem -->
            <!-- apex:outputLabel >Vendor Name</apex:outputLabel-->
            <!-- apex:outputField value="{!request.Company_Name__c}" /-->
        <!-- /apex:pageBlockSectionItem-->
         <apex:pageBlockSectionItem >
         	<apex:outputLabel >Same as Venue Details</apex:outputLabel>
            	<apex:actionregion >
              <apex:inputField value="{!request.Same_as_Venue__c}">
            		<apex:actionSupport event="onclick" action="{!getsameAddress}" />
            	</apex:inputField>
            </apex:actionregion>
        </apex:pageBlockSectionItem>
   </apex:pageBlockSection>
    <apex:pageBlockSection id="pbs">
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Phone</apex:outputLabel>
            <apex:inputField value="{!request.Company_Phone__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Address</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_Address__c}" styleClass="longinput"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >City</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_City__c}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Postal Code</apex:outputLabel>
            <apex:inputField required="true" value="{!request.Company_Postal__c}"/>
        </apex:pageBlockSectionItem>
        
        <!-- 
        This is a little complex...
        The action region allows the page to only submit this specific field
        to the controller when calling AJAX functionality. Without the action region,
        required fields cause the rerender action to fail.
        -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel >Country</apex:outputLabel>
            <apex:actionRegion >
            <apex:inputField required="true" value="{!request.Company_Country__c}">
                <apex:actionSupport event="onchange" reRender="vendorstate"/>
            </apex:inputField>
            </apex:actionRegion>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>

 

Avidev9Avidev9
The new pageblock section is for rerendering the fields that you want to populate.
impalacrazy69impalacrazy69

OK so i've changed the code to be a simple click command link to pass data. My renders and action regions are working fine. But there is no data being passed. I realized that i had the field backwards in my controller and fixed that but still nothing. So below you will see i put a value in one of the fields and when the function is called it shows up in the field. So hopefully someone will see what im missing on why the field from the form is not being passed into the field i want. Im wondering is i need sometihng else in my pagereference to pull and store the data from the current form and then push into the fields i want...

 public PageReference getsameAddress (){ 
        	this.request.Company_Address__c = 'see if it says something';
       		this.request.Company_City__c = this.request.Venue_City__c;
       		this.request.Company_Postal__c = this.request.Venue_Postal__c;
       		this.request.Company_Country__c = this.request.Venue_Country__c;
       		this.request.Company_State__c = this.request.Venue_State__c;
                
      return null;
    } 

 so right now the company address field is reading what i have. So i know the call and action is working...