Correct use of :complete and :before on a text_field_with_au

Hey guys!

Having a problem here figuring out how to use my :before and :complete
statements in a text_field_with_auto_complete construct.

At the moment, I have this bit of code within an edit.rhtml file:

  <%= f.text_field 'publisher_id', :size => 7 %>
  <%= observe_field(:item_publisher_id,
                    :frequency => 0.1,
                   # :update => :publisher_name,
                    :before =>

“Element.show(‘publisher_background_activity’)”,
:complete =>
“Element.hide(‘publisher_background_activity’)”,
:url => { :action
=> :auto_complete_publisher_name_for_id },
:with => “‘id=’ + encodeURIComponent(value)”
) -%>
<%= text_field_with_auto_complete :publisher,
:name,
{
:value =>
@item.publisher.name,
:size => 60
},
{
:frequency => 0.5,
:before =>
“Element.show(‘publisher_background_activity’)”,
:complete =>
“Element.hide(‘publisher_background_activity’)”,
:after_update_element =>
‘auto_complete_on_select’,
:min_chars => 2
}
-%>

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.

How do I do that?

Thanks in advance,

Daniel Buus

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.

On Feb 19, 10:24 am, “Daniel Smedegaard B.” [email protected]

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.

Hm! :slight_smile:

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?

http://agilewebdevelopment.com/plugins/model_auto_completer

? If you really need both text fields in the interface it won’t apply
though.

– fxn

On Feb 19, 12:05 pm, Xavier N. [email protected] wrote:

? If you really need both text fields in the interface it won’t apply
though.

Didn’t know about that one, no - thanks :slight_smile:

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 :wink: But I can use that plug on other projects of mine,
so thanks for the link!

Daniel

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 :wink: 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.

– fxn

On Feb 19, 2:12 pm, Xavier N. [email protected] wrote:

Ah okay, I just read the doc about trailing integers. Didn’t know it
was configurable, but that’s even better then! :smiley:

Cheers

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs