oakmac / autocompletejs

AutoCompleteJS Widget
Other
72 stars 14 forks source link

I need the next level of example for setValue() please #81

Closed MajorKusinagi closed 10 years ago

MajorKusinagi commented 10 years ago

Hello again!

Your previous help got me moving right along, and I'm almost done fully implementing what i want to accomplish, but I'm having a little difficulty with the setValue() method.

In your documentation you say: "You can use a String as shorthand for a Token Object when using setValue."

But how is it done exactly, not using shorthand?

You see, I have an autocomplete all set up on my project for brokers. At my company, brokers have a name, and an internal broker code... i.e. "Aon Broker" and "AONO0001"

Right now, my autocomplete shows "Aon Broker (AONO0001)" in the dropdown, and only shows the name (without the code) as a token when selected.

So if a user selects a report they were working on but did not finish yet, it should load up any saved values when they select it (their in-progress report).

At this point, I have the brokerName, and brokerCode and I just want to make a token out of them and set the autocomplete's value to that token. So I need a quick 2nd level setValue() example I guess?

I set my original array up like this: var brokers = [ { value: { brokerName: 'Alex Broker 1', brokerCode: 'ALEX0026' } }, { value: { brokerName: 'Aon Broker 1', brokerCode: 'AONR0006' } },
{ value: { brokerName: 'Aon Broker 2', brokerCode: 'AONR0029' } }, ... ];

Now in my loadInProgressReport() function I have an initialized autocomplete and I just want to set the token that's shown to the right broker... So I tried... var chosenBroker = { value: { brokerName: report.brokerName, brokerCode: report.brokerId } }; brokerWidget.setValue([chosenBroker]); but I'm just getting Error 6823 no matter what I try.

MajorKusinagi commented 10 years ago

Sorry nevermind, I actually figured it out!

var chosenBroker = { tokenHTML: report.brokerName + ' (' + report.brokerId + ')', value: report.brokerId }; brokerWidget.setValue([chosenBroker]);