Quote:
>> > I'm using an input box with an autocompleter with local data, like
>> > this:
>>
>> > >> var persons = [{name : "John"}, {name : "Carl"}, {name : "Susan"}];
>> > >> $('#inputname').autocomplete({ data: persons, (...) });
>>
>> > And was trying to see if i could update the local data by adding
>> > another object to persons:
>>
>> > >> persons[persons.length] = {name: "New Name"};
>>
>> > But theautocompletedoesn't read the data dynamically and it seams to
>> > only read the data on load. I tried with:
>>
>> > >> $('#inputname').autocomplete("setData", { data: persons, (...) });

Workaround:
>>> $('#inputname').autocomplete().trigger('setOptions',{
>>>     data: persons,
>>>     option2: value2
>>> })

Details:
There are two sets of functionalities here:
1) the jQuery UI widget methods, called as $(...).autocomplete
('setData', newSettings), and
2) the underlying jQuery object's bound events, which work like every
other jQuery event
$(...).trigger('setOptions',dataArray)

The setData method is supposed to trigger the underlying jQuery
setOptions event (this event is not on the input, but on the
autocomplete widget object).
When called using 'trigger', a function bound to the setOptions event
(or any jQuery event) recieves 2 arguments as follows: type (a string
with the event type), data (additional data for the event). In this
case, the data should be an object with the new options to be set.
However, the setData method takes two arguments - key, value - and
passes them on to the setOptions trigger, as an object literal. If
newSettings is an object/array with all the options to change, that
object will go into the 'key' variable, and passed as the key of the
object literal; while the value remains undefined.

The following will not work:
>>> $('#inputname').autocomplete('setData','data',persons)
because setData encases persons in an array, and the setOptions
trigger will not be able to find the string 'data' within the array,
as the array only contains the persons object.

The same holds true for any other options.

The simplest solution would be to change setData, so that it passes
the key:value as an object, not as an object within an array.
However, doing so removes some of the elegance of the setOptions, as
you cannot set more than one option using setData, and you can set
multiple options using setOptions, by passing an object literal.
On the other hand, setData has its own method for setting multiple
options - adding multiple key,value arguments - key,value,key,value
etc.

(I apologize for being so wordy. I hope this helps the developers fix
the problem, and users to make use of the autocomplete until it is
fixed.)

On Nov 14, 3:50 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]>
wrote:
> There is a now a ticket for this issue:http://ui.jquery.com/bugs/ticket/3584
>
> Jörn
>
> On Thu, Oct 23, 2008 at 10:11 PM, Fotinakis <[EMAIL PROTECTED]> wrote:
>
> > I am also having this issue and can't find a way to fix it.setData
> > doesn't seem to actually update any of the options that were set on
> > load. This may be just my misunderstanding of how the plugin works,
> > but on line 625 we see this code:
>
> > if ( "data" in arguments[1] )
> >     cache.populate();
>
> > In testing this, the execution doesn't ever seem to reach the
> > cache.populate() code because arguments[1] is *always* (as far as I
> > can tell, passing in different options) an _empty_ struct no matter
> > what struct of options is passed in.
>
> > Thanks to anyone who could shed some light on this!
>
> > On Oct 8, 2:22 pm, mario <[EMAIL PROTECTED]> wrote:
> >> I also tried to use "flushCache" but I think that works only for
> >> remote data.
>
> >> On Oct 8, 3:09 pm,mario<[EMAIL PROTECTED]> wrote:
>
> >> > Hi,
>
> >> > I'm using an input box with an autocompleter with local data, like
> >> > this:
>
> >> > >> var persons = [{name : "John"}, {name : "Carl"}, {name : "Susan"}];
> >> > >> $('#inputname').autocomplete({ data: persons, (...) });
>
> >> > And was trying to see if i could update the local data by adding
> >> > another object to persons:
>
> >> > >> persons[persons.length] = {name: "New Name"};
>
> >> > But theautocompletedoesn't read the data dynamically and it seams to
> >> > only read the data on load. I tried with:
>
> >> > >> $('#inputname').autocomplete("setData", { data: persons, (...) });
>
> >> > AND by destroying theautocompleteand resetting theautocomplete:
>
> >> > >> $('#inputname').autocomplete("destroy");
> >> > >> $('#inputname').autocomplete({ data: persons, (...) });
>
> >> > but none seemed to work.
>
> >> > Is there anyway to accomplish this, I prefer to load the data locally
> >> > to minimize the load on the server...
>
> >> > Thanks,
> >> >Mario

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to