Hi Jon
Ah, I see what you mean. Looking at your code, I think there were
actually two issues:
[1] You need to make your "makes", "models", etc. arrays observable
otherwise changing them isn't going to be reflected in the UI
[2] The jQuery UI autocomplete facility requires you to use some
different syntax if you want to change what autocomplete options are
associated with a form field that the user has already got focused.
Specifically, you have to trigger its "setOptions" event, and then it
will update properly.
To see how making these changes gets it to work, check out the code at
http://pastie.org/1172054. A few more points to note:
* Instead of having global arrays of autocomplete data (e.g.,
"models", "engines", etc.), I've made the autocomplete data a separate
property of each line. That way you can edit multiple lines at the
same time, and they each display the autocomplete options relating to
themselves, independently of the other lines.
* To ensure that any characters the user has typed into a box before
the autocomplete appears aren't erased when it does appear, I've used
"valueUpdate: 'afterkeydown'". This keeps the view model instantly in
sync with the view. Without this, things still work, but if you happen
to be pressing a key at the wrong moment, your key press could be
wiped out.
IMPORTANT: I've only just added 'afterkeydown' support to KO. To see
this example code working, be sure to use the latest Knockout code
from
http://github.com/SteveSanderson/knockout/tree/master/build/output/
Cheers
Steve
On Sep 17, 8:54 am, MrTea <
hilton....@gmail.com> wrote:
> Hi Steve,
>
> Thanks for your response, I hope Knockout gains traction amongst
> developers, it certainly seems to be off to a flying start.
>
> Re our Autocomplete example. The complication is that we have several
> "layers" of autocomplete (several cascading text boxes) and a lot of
> data so it's not practical to load the entire autocomplete graph (for
> want of a better word) into memory when the user accesses the page.
>
> So the question is how we change your example to load the relevant
> autocomplete data as needed.
>
> We had a stab at this as you can see herehttp://
pastie.org/1164445
> but then ran into the issue of the autocomplete data being loaded too
> late.
>
> Kind Regards,
> Jon Hilton
>
> On Sep 16, 5:43 pm, "
st...@codeville.net" <
fla...@gmail.com> wrote:
>
>
>
> > Hi Jon
>
> > I had a go at implementing roughly what you describe (by modifying the
> > Cart Editor example) and it worked out pretty well - only a few
> > alterations to the example needed. Could you try out the code athttp://
pastie.org/1163150andsee if it matches what you're trying to