Daniel Smedegaard Buus
2007-Feb-19 09:24 UTC
Correct use of :complete and :before on a text_field_with_auto_complete?
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 } -%> <span id="publisher_background_activity" class="ajax_work_indicator" style="display:none;">...</span> --------- 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Smedegaard Buus
2007-Feb-19 10:57 UTC
Re: Correct use of :complete and :before on a text_field_with_auto_complete?
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 Buus" <danielb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > } > -%> > <span id="publisher_background_activity" > class="ajax_work_indicator" style="display:none;">...</span> > --------- > > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Smedegaard Buus
2007-Feb-19 11:05 UTC
Re: Correct use of :complete and :before on a text_field_with_auto_complete?
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! :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Feb-19 11:05 UTC
Re: Correct use of :complete and :before on a text_field_with_auto_complete?
On Feb 19, 2007, at 10:24 AM, Daniel Smedegaard Buus 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Smedegaard Buus
2007-Feb-19 12:47 UTC
Re: Correct use of :complete and :before on a text_field_with_auto_complete?
On Feb 19, 12:05 pm, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Feb 19, 2007, at 10:24 AM, Daniel Smedegaard Buus 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. >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! Daniel> -- fxn--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2007-Feb-19 13:12 UTC
Re: Correct use of :complete and :before on a text_field_with_auto_complete?
On Feb 19, 2007, at 1:47 PM, Daniel Smedegaard Buus 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. -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Smedegaard Buus
2007-Feb-19 14:08 UTC
Re: Correct use of :complete and :before on a text_field_with_auto_complete?
On Feb 19, 2:12 pm, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Feb 19, 2007, at 1:47 PM, Daniel Smedegaard Buus wrote: > > 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. >Ah okay, I just read the doc about trailing integers. Didn''t know it was configurable, but that''s even better then! :D Cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---