SalesforceFoundation / visualforce-typeahead

A flexible typeahead component for use on Visualforce pages. Uses the typeahead.js library from Twitter.
BSD 3-Clause "New" or "Revised" License
73 stars 37 forks source link

Update to support actionSupport with event=onchange #8

Open thvd opened 10 years ago

thvd commented 10 years ago

You can now support the onchange event. For reference see: http://stackoverflow.com/questions/2026704/what-event-can-be-captured-when-an-html-hidden-input-value-is-set-changed

thvd commented 10 years ago

Sorry, this is not going to work. We should think about some other solution.

groundwired commented 10 years ago

Why didn't it work?

thvd commented 10 years ago

I tried the following:


<c:Typeahead searchBoxId="templateSearch" object="Template__c" destinationForSelectedId="templateId" destinationForSelectedValue="templateName" />
<apex:inputHidden id="templateId" value="{!templateId}">
    <apex:actionSupport event="onchange" action="{!fetchTemplate}" rerender="linkPanel"/>
</apex:inputHidden>

But when I added the .change() call to the JavaScript it did not trigger the fetchTemplate actionSupport action.

groundwired commented 10 years ago

The top item on my list of possible improvements is to add an optional parameter to the component called onSelection or selectionAction or something like that. I had thought that would be a javascript function (which could in turn call an actionFunction to run apex) but it could possibly be an apex method. I think this would accomplish what you want.

Afraid I don't have time to take it on right now, but will keep it in the backlog.

thvd commented 10 years ago

This morning I did some further research and found that using a non-hidden <apex:inputText> works.

Example:


<apex:inputText id="templateId" value="{!templateId}" style="display: none;">
    <apex:actionSupport event="onchange" action="{!fetchTemplate}" reRender="linkPanel"/>
</apex:inputText>