Git Product home page Git Product logo

visualforce-typeahead's Introduction

visualforce-typeahead

A flexible typeahead component for use on Visualforce pages. Uses the typeahead.js library from Twitter.

Use this component to provide a lookup field for related objects, such as the account for a contact.

Typeahead Lookup Example Page

###Installation Click here to install: https://githubsfdeploy.herokuapp.com/?owner=SalesforceFoundation&repo=visualforce-typeahead

###Video Intro A 4-minute video showing the basic functionality: http://youtu.be/Cc87v39Z9tY

###Usage If you include the component on a Visualforce page in its simplest form, it will search Contacts:

<c:Typeahead />

For other objects, pass in the object parameter:

<c:Typeahead object="Account" /> 

For an example of the component in use, see the TypeaheadTest page.

###Component Attributes

There are many attributes you can pass to the component to change its behavior. For example, the following searches Accounts and puts the ID it finds into a hidden field you can access in your controller.

<h3>Account Name:</h3>
<c:Typeahead object="Account" destinationForSelectedId="accountId" />	
<apex:hidden id="accountId" value="{!accountId}" />		

This table lists the attributes:

Attribute Type Description Default
searchBoxId String Id attribute for the search input box. searchBox
styleClass String CSS class attribute to apply on the search input box.
style String CSS style attribute to apply on the search input box.
placeholder String Text to display as a placeholder in the search input box. Search
object String The type of record we are searching. Contact
objectIdField String The field that provides the object Id. Id
primaryField String The field that provides the primary display value. Name
secondaryField String A field to differentiate the display value. Appears in parens.
minSearchLength Integer How many characters you must type before searching. Must be 2 or more. 2
searchScope String Indicates which types of fields on the object to search. One of ALL, NAME, EMAIL, PHONE, SIDEBAR. ALL
filterClause String WHERE clause to filter records. Do not include WHERE.
orderBy String Name of field to sort records by. Name
recordLimit String Maximum number of records to return to the list. 2000
destinationForSelectedId String Id of a field, such as an apex:inputHidden, that should get Salesforce Id of the selected item.
destinationForSelectedValue String Id of a field, such as an apex:inputHidden, that should get the displayed name/value of the selected item.
stealFocus Boolean Whether to automatically move the focus to the search box when the component is displayed. true

###Possible Improvements

  • pass in a function to call when something is selected (so they don't have to click a button)
  • specify where to put errors (and then use an alert if not specified)
  • specify when to show secondary field (all the time or only when needed to make name unique)
  • attribute to pass in HTML suggestion template, or function to render the template
  • list of extra fields to query (especially if needed for suggestion template)
  • option to use SOQL instead of SOSL - less flexible but faster and possibly more reliable

###License This project is released for your page-designing pleasure by the Salesforce Foundation Business Applications Team under the open-source BSD license. Contributors to the project are welcome.

visualforce-typeahead's People

Contributors

ceiroa avatar svc-scm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

visualforce-typeahead's Issues

component fails to load on visualforce rerender

Steps to reproduce:

  1. Update TypeaheadTest to embed interface within form tags
  2. add commandbutton to refresh form

Code should now look like:
`
<apex:page showHeader="true" sidebar="true" title="Typeahead Test Page">

<style>
    .sample-form { 
        margin: 20px;
        width: 400px;
        font-size: 16px; 
    }
    .sample-form h3 { 
        margin:8px 0; 
        display:block; 
    }
    .sample-form button { 
        margin: 18px 0; 
        padding: 5px 10px;
    }
</style>

<apex:form id="theForm">

<div class="sample-form">

    <h3>Contact Name:</h3>
    <c:Typeahead /> 

    <button onclick="alert( 'You selected ' + document.getElementById('searchBox').getAttribute('data-id') );">Submit</button>

    <h3>Account Name:</h3>
    <c:Typeahead searchBoxId="acctSearchBox" object="Account" primaryField="Name" secondaryField="BillingCity" 
            searchScope="NAME" placeholder="Type something..." minSearchLength="3" 
            destinationForSelectedId="accountId" destinationForSelectedValue="accountName" stealFocus="false" />  

    <input type="hidden" name="accountId" id="accountId" />     
    <input type="hidden" name="accountName" id="accountName" />     

    <button onclick="alert( 'The hidden Id field contains ' + document.getElementById('accountId').value + '\nThe hidden Name field contains ' + document.getElementById('accountName').value );">Submit</button>
    <apex:commandButton id="refreshButton" rerender="theForm" value="Refresh" />

</div>
</apex:form>

</apex:page>`

  1. run page and click "Refresh" - you should see the Typeahead component fail to load

I've narrowed the issue down to the Typeahead component line 14 window.typeahead || document.write('<script src="{!URLFOR($Resource.Typeahead, '/typeahead.bundle.min.js')}"><\/script>'); - removing this allows refresh, although without this library obviously typeahead won't work.

SOSL or SOQL

Just install the package, and it can't work at all!!

After the debug, I found it is beacuse of the SOSL problem.

I dont know the reason, however, the SOSL returns nothing at all. You can see it in the attached screenshot.
image

I double check the global search functionality as well. And, it confirms the problem of SOSL. The SOSL at the moment is not function.

After modify the class a little, and change to use SOQL. The problem is gone, and all the feature of typeahead works as it should be.

Since the fact, I suggest to add the option for users to use SOQL.

Thanks.

The Multiple Values selection capablity

This is overall good Feature so far , until user is is coming up with the functionality like want to use the lookup for emails like functions , Where in To or CC we want to search contact and add multiple contacts's email in same search , This is Failed and following enhancement is possible

  1. Allow user to specify multi select Mode
  2. While one or more values already Selected do prepare Query String based on new value
  3. Allow Delete the Selected Values
  4. Wile Selecting other values previous selection should not disappear
  5. The id should be coped in the hidden field by comma separated List

error when trying to use in iframe

Hey Evan, trying to use the typeahead component in an iframe (popup window) but I get an alert box that says:
"Javascript proxies were not generated for controller Typeahead: may not use public remoted methods inside an iframe."

Any idea on how to solve that?

Problem with pressing enter after selection

  1. Type something that results in a list longer than one value.
  2. Press down arrow to select a value other than the first one in the list, and then press Enter.

Your value is selected.

  1. Press Enter again.

The first value in the list appears as if you selected it.

Bug when only destination for ID and not value is defined

Found a little bug, I think. When invoking the component I only had the destinationForSelectedId attribute defined and did not have destinationForSelectedValue defined. That used to work fine but at some point must have stopped working. It was bonking on line 137 in Typeahead.component, throwing the error "Syntax error, unrecognized expression: [id$=]" due to the blank destinationForSelectedValue attribute:

135 // if destinations are defined, set them too
136 j$('[id$={!destinationForSelectedId}]').val( id );
137 j$('[id$={!destinationForSelectedValue}]').val( value );

I fixed my issue by adding the destinationForSelectedValue attribute to the component call but wanted to let you know. Can't quite figure out why it used to work and stopped at some point.

onkeyup behavior

The current onkeyup behavior is to clear the selection if they clear the box completely.

There's a bug.

Let's see the circumstance:

(1) User enter 'sFo' and the suggestion hints there's an account named 'sForce'.
(2) User click the suggested item and get the Id of the 'sForce'
(3) User just enter one "backspace", and the input value now is 'sForc'.
(4) Now, user hits 'Submit', The id of 'sForce' shows. It should not shows, since there's no such a 'sForc' account.

It should be changed to clear anytime the input is modifed (on every keyup). That is just to remove the if condition in the Line#221,222,224.

a is undefined error

I'm gettting this error: "a is undefined"
/*!

!function(a){var b={isMsie:function(){return/(msie|trident)/i.test(navigator.userAgent)?navigator.userAgent.match(/(msie |rv:

filterClause returning no results

Not sure if I'm just missing something, but I can't get any results to return while using the filterClause attribute.

I'm using: filterClause="Product_Family__c = 'Hearth'" Pretty sure that's correct syntax for a WHERE clause in SOSL. I don't get any errors or anything, just no results. Am I missing something?

Also, assuming I can correct this, will the attribute accept a merge field? Eg. filterClause="Product_Family__c = '{!prodtype}'"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.