Basically, this creates two input fields, one where you can put in an
ID of a publisher, and another, where you can write text, and AJAX is
used to fetch publishers whose names contain that text.
As it is stands, everything works like expected, except for the
showing and hiding of my span which indicates that something’s
happening behind the scenes. It works on the first input field which
uses observe_field - it shows when the user inputs something and
disappears once the result is returned. But on the
text_field_with_auto_complete, the div is not shown and hidden before
the moment you select one of the items on the list that is returned by
the AJAX call. I’d like for it to be shown once the call to lookup
names in the database is initiated, and to be hidden once the list is
delivered to the browser.
Actually, I believe the reason it shows and hides the div at all has
nothing to do with the statements in the auto_complete field, but in
the fact that the ID input field is updated as a result of the
auto_complete field, which fires the ID field’s AJAX operations. So,
the :before and :completes on the auto_complete field do nothing,
really.
Okay, forget it. Found the :indicator property. It really bugs me that
a) The consistency between properties and methods on different AJAX-
based form helpers is shabby to say the least
b) The API documentation on this part of Rails is so sparse. You have
to skate around between different classes, and often you don’t find
the right information for that particular helper derived from some
parent class, like in this example, where Google finally served me a
page with a description of the :indicator property.
On Feb 19, 2007, at 10:24 AM, Daniel Smedegaard B. wrote:
Basically, this creates two input fields, one where you can put in an
ID of a publisher, and another, where you can write text, and AJAX is
used to fetch publishers whose names contain that text.
Just for the record, are you aware of the plugin model_auto_completer?
? If you really need both text fields in the interface it won’t apply
though.
Didn’t know about that one, no - thanks
But, as it turns out, I need the user to be able to manually type in
the ID and get the corresponding name, and be able to type in a
fragment of a name, then get the ID. Besides that, not all my primary
keys are integers, so that plugin won’t work. This is a seriously
specialized app But I can use that plug on other projects of mine,
so thanks for the link!
On Feb 19, 2007, at 1:47 PM, Daniel Smedegaard B. wrote:
But, as it turns out, I need the user to be able to manually type in
the ID and get the corresponding name, and be able to type in a
fragment of a name, then get the ID.
OK, yeah the plugin does not help then.
Besides that, not all my primary
keys are integers, so that plugin won’t work. This is a seriously
specialized app But I can use that plug on other projects of mine,
so thanks for the link!
Good. Note however that the plugin does not assume the key is an
integer. The key is extracted with a regexp from the ID attribute of
LIs. That regexp is “(\d+)$” by default (extract trailing integers),
but is configurable.