You need to sign in to do that
Don't have an account?
MTBRider
Two Questions: Using onblur instead of onchange & default field behavior in VF pages
I have two questions:
1. onChange does not work on a Lookup field. The recommendation is to use onblur, but I am unsure on how to use it. When the user clicks on the magnifying glass, onblur fires but no changes have been made yet. If my action method is to perform a calculation based on the changed value in the lookup field, how do I do this if onblur is going to call the action method before any changes have been made?
2. I am creating a custom Opportunity screen with Visualforce. I am using the standard Opportunity controller with my own extension. I was under the impression that standard functionality of the Opportunity screen would still work. Specifically, in a standard Opportunity screen, probability percentage is driven by the sales stage that the user selects. Using the standard controller with an extension, this does not seem to work anymore. Selecting the Sales Stage does not automatically select a corrisponding probability percentage. Shouldn't it?
Thanks
2. the probability percentage is a dependent field, and dependent fields are not yet supported in Visualforce.
To get onchange type functionality to work I did this to lookup the Account Name when the Opportunity changed.
This needs a little improvement but I just got it working. I used the onfocus event of the controlling field to call an actionFunction.
<script type="text/javascript">
function oppFocused(oppId)
{
if(oppId.indexOf("Opportunity_lkwgt") > -1){
return;
}
var Opplkid = document.getElementById(oppId + '_lkid').value;
if(Opplkid != '000000000000000' && Opplkid != null){
lookupAccountName(Opplkid);
}
}
</script>
<apex:actionFunction action="{!lookupAccountName}" name="lookupAccountName"
immediate="true"
rerender="AccountName" id="AFlookupAccountName" >
<apex:param name="firstParam" assignTo="{!TSImpCont.TSImplementation.Opportunity__c}" value="" id="paramOppId" />
</apex:actionFunction>
.
.
.
<apex:inputField value="{!TSImpCont.TSImplementation.Opportunity__c}" id="Opportunity"
onfocus="oppFocused(this.id)" />
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Name" for="AccountName"/>
<apex:outputText value="{!AccountName}" id="AccountName"/>
</apex:pageBlockSectionItem>
Controller code:
// This method sets the AccountName value based on the Opportunity Id
public PageReference lookupAccountName(){
if(TSImpCont.TSImplementation.Opportunity__c == null){
return null;
}
AccountName = [select Account.Name
from Opportunity
where Id = :TSImpCont.TSImplementation.Opportunity__c][0].Account.Name;
return null;
}
Need to add code to only execute the soql if the opportunity id has changed.
If SalesForce changes the underlying lkid the code will no longer work.
I also suggest using onchanged on the opportunity to clear the account name. If the user types in the opportunity the account name will be cleared out. You could then perhaps set it when the record is saved.