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

Lookup onchange with actionSupport
Hi there. I have the following code that leverages a custom object called "Test__c", that has
1 field, which is a lookup to Accounts.
Now, when I type a value into the lookup box and I select a value from the autocomplete, the value in the "test" pageBlockSection will update in an Ajax fashion like so:

But when I use the lookup dialog to select an account, the field will not update:

Any ideas??
Thanks
1 field, which is a lookup to Accounts.
Code:
<apex:page standardController="Test__c" tabStyle="Test__c"> <apex:sectionHeader title="{!$ObjectType.Test__c.label} Edit" subtitle="New Test"/> <apex:form> <apex:pageBlock title="Test"> <apex:pageBlockButtons> <apex:commandButton value="Save" action="{!save}" /> <apex:commandButton value="Cancel" action="{!cancel}" /> </apex:pageBlockButtons> <apex:actionRegion> <apex:pageBlockSection title="Information"> <apex:inputField value="{!Test__c.Account__c}"> <apex:actionSupport event="onselect" rerender="otherPanel" /> </apex:inputField> </apex:pageBlockSection> </apex:actionRegion> <apex:pageBlockSection title="test" id="otherPanel" rendered="true"> <apex:outputField value="{!Test__c.Account__c}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Now, when I type a value into the lookup box and I select a value from the autocomplete, the value in the "test" pageBlockSection will update in an Ajax fashion like so:
But when I use the lookup dialog to select an account, the field will not update:
Any ideas??
Thanks
I've not found a solution yet, i'll post back here if i figure this out.
Message Edited by TehNrd on 12-10-2008 01:52 PM
That workaround seems like a prudent approach. :)
Regards
Not my optimal route albeit it works.
Would this be worth logging for the next release?
Kind regards
Has anyone found a solution for this? (In particular getting a lookup field to trigger a visualforce action and rerender)
Try using event="onblur"
I was dealing with this same issue and I ran across this thread. I am using event="oblur" in my actionSupport component and it is rerendering my components as expected whether the user enters information by hand or uses the look-up function. It does require that the user leave the field (in this case opportunity.accountId), but that seemed to be the case with event="onchange" as well.
-- Matt
That's what I'm using right now (in lieu of support for 'onchange') ... however it's not an ideal work around. I really need to execute the actionsupport when the content changes and not when the user tabs through the field.
Thanks though.
I'm curious to know if SF engineers are working to provide support for "onchange" events with lookup fields - or if it's just an issue we should plan to work around. Can anyone on the inside report?
- RW
Not sure if this will help your situation, but I am checking to see if the data has actually changed in the getter for my rerendered components and when the lookup field doesn't change, my components don't appear to rerender. I agree it isn't ideal though.
-- Matt
Ron,
Is there a solution for this yet? I am currently using the onblur event, but it doesn't give me quite the behavior i want.
Thanks!
@mattdarnold
How do you that? Can you provide some sample code? I am stuck in the same problem.
Hi Guys,
Has anyone found a fix for this? OnBlur works great as a workaround.
Cheers
Paul
Back to top with this one...
This thread started quite a while ago, and there isn't a resolution yet. It seems like a pretty basic thing to have lookup fields work similarly to the other fields and trigger an 'onchange' event. Is there any method we can use to bring some attention to this longstanding issue?
Has anyone posted an Idea on this yet?
Can someone from SalesForce let us know if this is being looked at?
Thanks,
Rich C.
There is an idea posted:
https://sites.secure.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=08730000000HD0MAAW
Go vote it up everyone!
Thanks,
Rich C.
I've hacked this up as a proof of concept and it seems to work fine in Chrome. It would need some cleaning up for IE seeing that it uses a different event listener call, etc.
It's super-ugly!!! :-)
1. In essence, set an onClick event of your own not on the *lookup* field, but on the Icon the user clicks to do the Lookup.
2. That event starts an interval timer that polls the field to see if it changes, and if it does, calls the specific onChange function.
Polling is very ugly, however since we know we're dealing with events at "user-speed", we can poll infrequently (I used 1/2 second), and we can limit the number of times we poll such that if the user doesn't choose an object using the lookup within a given period (I chose 60 seconds), the onChange wouldn't fire. (So, that's a gap, but it limits the time this loop will be running.)
So, if you really can't use onBlur, this seems to do the job. Again, it's a proof of concept and it's late. :-)
Best, Steve.
Steve,
Putting the event on the lookup icon and starting a timer is clever. I pondered a couple workarounds usign the lookup icon, but didn't think of this.
I'll try to spend some time on it this evening and get it working in jQuery to eliminate the cross browser event problems and post my results.
If someone around here has some extjs-fu and wants to get it working that would be appreciated as well! Then people could use this w/o bringing in another javascript library.
Thanks,
Rich C.
A little friendlier, but I still haven't addressed IE. Sigh.
Hi All,
I was having issues with this as well. After beating my head against the wall I think I may have discovered why it is not working. If this is old news, sorry for re-posting. I am only including the code that is relevent to the issue.
Here is the piece from my VF page
Here is the refreshTask code
I was having problems with even just getting the action fire, or so it would seem. Once I change the refreshTask to return null, the onchange started working. Not sure why or if it is the correct thing to do but it works at this point :-). I have only tested the onchange part in the various browsers so not sure if there will be other issues but it seems to work as expected at this point.
If this does not work you, please post back so hopefully we can get this resolved and move on.
Jason