You need to sign in to do that
Don't have an account?

dynamically populating the inputfields
Hi everyone,
I am working with lookup field in my page which is looking to the same object and wen i selectesd some value using lookup field then i want the rest of input fields values of my visualforce page to be automatically populated once i click button ..so as iam new to visual force development i dont have any idea whether its possible if possible how to do that ..just give an example of achieving it......
my code is as follows....
<apex:page standardController="CAF_Bank__c">
<script>
function autopopulate()
{
<!--it should autopopulatethe rest of fields related to the object which iam looking over through the lookup-->
}
</script>
<apex:form >
<apex:pageBlock title="My Content">
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:pageBlockSectionItem >
<!-- <apex:outputLabel value="Lookup to an Contact" for="theLookup"/>-->
<!--<apex:inputField id="theLookup" value="{!CAF_Bank__c.caf_lookup__c}"/>-->
<apex:outputLabel value="BranchCode" for="theLookup"/>
<apex:inputField id="theLookup" value="{!CAF_Bank__c.caf_lookup__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Bank Name "/>
<apex:inputField id="bname" value="{!CAF_Bank__c.Bank_Name__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Branch Name "/>
<apex:inputField id="branchname" value="{!CAF_Bank__c.Branch_Name__c}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton value="Autopopulate" onclick="autopopulate()"/>
</apex:form>
</apex:page>
Thanks&Regards,
Anu......
So are you saying that when the user chooses a lookup, it should fill in the rest of the input fields using the looked up object? If that is the case, you will need to pass the chosen lookup field back to the controller (which will happen automatically, because you have used an sobject field to back the lookup).
Then you will need to populate the sobject backing the various other input fields based on the lookup id. At the moment it appears that you are trying to use the same sobject, which I can't see working.
I'd suggest making your commandbutton invoke an action method to set this stuff up rather than going off to javascript.
hi bob,
thanks for your repy, i do agree with ur suggestion..But i find diffuculty in doing all stuff in d controller as u suggested ..
so plz give me a working example in achieving my requirement....so that i can understand the way i have to do it..
Thanks& Regards,
Anu...
I don't have any examples of this that I can just paste in I'm afraid.
Happy to assist if you can post your code and details of problems.
hi bob ,
thanks as u said u r happy to help me ,great to have such a strong support.as u told i would like to clearly explain my problem ..this is my visualforce page..
<apex:page standardController="CAF_Bank__c" extensions="lookup3">
<script>
function branchpopulate()
{
<!-- here iam trying to fetch the list which is having queried output ie branchname field value corresponding to record whose branchcode value==lookup field value values -->
var myArray = new Array();
myArray= '{!CurrentBranchList}'.replace('[','').replace(']','').split(',');
var currbranchname=myArray;
alert(currbranchname);
<!--but currbranchname is displaying some strange values but not the exact branch name corresponding to a record which i queried in d controller so plz correct me how to do this task of fetching that record related to my lookup field value and populate those values to ui ie visualforce page....--> document.getElementById('{!$Component.form1.branchname}').value=currbranchname;
<!--here iam popuilating branch code value to the visualforce page inputfield value-->
return false;
}
</script>
<apex:form >
<apex:pageBlock title="My Content">
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="BranchCode" for="theLookup"/>
<apex:inputField id="theLookup" value="{!CAF_Bank__c.caf_lookup__c}" />
<!--i want to pass this lookup field valuue to my controller so i have to filter query using this value,but iam not able to pass it i am able to pass textfield value using setters and getters but iam not able to pass this lookup fielsd value plz tell me how to pass this value to controller -->
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
<apex:outputLabel value="Bank Name"/>
<apex:inputField id="bname" value="{!CAF_Bank__c.Bank_Name__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Branch Name "/>
<apex:inputField id="branchname" value="{!CAF_Bank__c.Branch_Name__c}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton value="autopopulating" onclick="branchpopulate()"/>
</apex:form>
</apex:page>
My controller is as follows:
So finally what iam trying to do here is just passing lookupfield value to controller and query the record related to that lookupfield value and pass thiss queried output to vpage and automatically populate those values to the input fieldsup onselecting any lookup field value in vfpage..
So bob if iam not clear to u abt my requirement plz let me know.and plz correct my mistakes so that io can fulfil my requirement...
Thanks&Regards,
Anu....
<apex:inputField id="theLookup" value="{!CAF_Bank__c.caf_lookup__c}" />
Hi bob,
Yes you r right that currentbranch list contains a single branch name which i am calling in vpage and assigning to an array so that i can assign the input field value with this currentbranchlist...that is what iam trying to do... and asyou said iam trying to use this userchosen lookup field to filter my result...hope you clearly understood my problem now.....
so y iam not able to dothis particular functionality, is dere any were iam going wrong if so please assist me in solving my issue...
Thanks&Regards,
So if you are only ever populating the branch name with a single string, don't store it in a list and mess around converting it to an array, store it as a string property in the controller and use that in the page.
What problems are you seeing with regard to the lookup field? Is it not getting set in the controller?
I suggest you add some system.debug statements to ensure that the data you have in the controller matches what you expect - attempting to figure out what's going on from the page and javascript is a painful process.
Hi bob,
Thanks for your reply, s i will do as if u suggested,and ur rite that lookup field is not getting set in the controller,...
Thanks®ards,
anu....