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.)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---