Sandeep Gudibanda
2008-Jul-19 19:46 UTC
text_field_with_auto_complete - Trigger on NonSelecting
Hi, I am using text_field_with_auto_complete on a field. I update a part of my page if user chooses any particular option listed by auto_complete list. To do this I call and remote_function with :after_update_element. But I also wanna update a part of my page if user doesn''t select anything from the autocomplete list. For EX: I want to Bring it to notice of the user that the "Name" that he has not entered is not in our database. The div like below should be higlighted <div id ="error_box" class="error_box" style="display:none"> <span class="showtext bold"> Hospital entered was not found. Please enter the details here: </span> </div> So what I need to do is : When control moves out of the field on which auto_complete is enacted, and when user doesn''t select any option listed by auto_complete, I want to trigger a different action. I tried to simulate this using text_field_with_auto_complete along with observe_field :on => :change. It didn''t help, as onChange gets triggered on both cases: User selecting one option from the list and User entering a new Name. How can I solve this? Please suggest. Regards, SG -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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
2008-Jul-20 21:39 UTC
Re: text_field_with_auto_complete - Trigger on NonSelecting
On Sat, Jul 19, 2008 at 9:46 PM, Sandeep Gudibanda <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am using text_field_with_auto_complete on a field. I update a part of > my page if user chooses any particular option listed by auto_complete > list. To do this I call and remote_function with :after_update_element. > > But I also wanna update a part of my page if user doesn''t select > anything from the autocomplete list. > > For EX: I want to Bring it to notice of the user that the "Name" that he > has not entered is not in our database. The div like below should be > higlighted > > <div id ="error_box" class="error_box" style="display:none"> > <span class="showtext bold"> Hospital entered was not found. Please > enter the details here: </span> > </div> > > So what I need to do is : When control moves out of the field on which > auto_complete is enacted, and when user doesn''t select any option listed > by auto_complete, I want to trigger a different action. > > I tried to simulate this using text_field_with_auto_complete along with > observe_field :on => :change. It didn''t help, as onChange gets triggered > on both cases: User selecting one option from the list and User entering > a new Name.model_auto_completer (http://agilewebdevelopment.com/plugins/model_auto_completer) needed something similar. In this case the feature is to rollback to the last valid completion if the user enters free text. To accomplish this the textfield has a custom cache attribute. When the user selects some completion the cache is reset in :after_update_element. There''s an onblur handler that compares the cache to the current value, and rollbacks if they are different. In your case you''d show the warning. That''s the basic idea, have a look at its implementation for further details. --~--~---------~--~----~------------~-------~--~----~ 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
2008-Jul-20 22:20 UTC
Re: text_field_with_auto_complete - Trigger on NonSelecting
On Sun, Jul 20, 2008 at 11:39 PM, Xavier Noria <fxn-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> To accomplish this the textfield has a custom cache attribute. When > the user selects some completion the cache is reset in > :after_update_element. There''s an onblur handlerIt is an onchange handler currently. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sandeep Gudibanda
2008-Oct-06 07:26 UTC
Re: text_field_with_auto_complete - Trigger on NonSelecting
Hi Vinay, This shud help you, getCommunity is the action in my controller, which gets called after update. Also notice, that i get the id of chosen value by doing value.id , also events are captured in element and value. Hope this helps. <%= text_field_with_auto_complete ''salary_review'',''company'', {}, :skip_style => true ,:frequency => 0.1, :indicator => ''status-indicator'', :after_update_element => "function(element,value){" + remote_function(:update => ''salary_review_company'', :url => { :action => :getCommunity }, :with => "''id=''+ value.id ") + "}" %> If the user doesn''t choose any, i tried using observe_field. But it didn''t do too well, so i stopped using it. Regards, Sandeep G Vinay wrote:> Hi Sandeep, > Can you show me how to call a remote_function > with :after_update_element? I need almost the exact same > functionality. Once a user chooses an option from the autocomplete > list, i want to update a div with more information relating to the > selected option. Also, did you find a solution for when the user > doesnt select anything from the list? > Also, how did you manage to parse the id of the selected option along > with the form values? Mine is a belongs_to association and so i am > using model_auto_completer for now. I hope you can help me with this. > Here is my post on this > http://groups.google.co.in/group/rubyonrails-talk/browse_thread/thread/5a91ddc41c1c44d9 > > On Jul 20, 12:46�am, Sandeep Gudibanda <rails-mailing-l...@andreas--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Sandeep! will try this soon. "Events are captured in element and value". I dont quite understand that. Can you please explain? I dont know much of JS and am quite new to ROR too. Ideally, I want a functionality like Gmail''s To address bar. It should have autocomplete, find_or_create_by_email and an extra feature of a live search after_update_element which updates a div with more info about the contact using the email/name entered in the field. If the entered string does not match any results, it should validate for an email address and create a contact using that info alone. I know its a tall ask :).. but things are falling into place and I just thought it would be helpful to me if you had any tips since you seem to have done something similar to an extent. Thanks again! On Oct 6, 12:26 pm, Sandeep Gudibanda <rails-mailing-l...@andreas- s.net> wrote:> Hi Vinay, > > This shud help you, > getCommunity is the action in my controller, which gets called after > update. > Also notice, that i get the id of chosen value by doing value.id , also > events are captured in element and value. Hope this helps. > > <%= text_field_with_auto_complete ''salary_review'',''company'', {}, > :skip_style => true ,:frequency => 0.1, :indicator => > ''status-indicator'', > :after_update_element => "function(element,value){" + > remote_function(:update => ''salary_review_company'', :url => { :action => > :getCommunity }, :with => "''id=''+ value.id ") + "}" %> > > If the user doesn''t choose any, i tried using observe_field. But it > didn''t do too well, so i stopped using it. > > Regards, > Sandeep G > > Vinay wrote: > > Hi Sandeep, > > Can you show me how to call a remote_function > > with :after_update_element? I need almost the exact same > > functionality. Once a user chooses an option from the autocomplete > > list, i want to update a div with more information relating to the > > selected option. Also, did you find a solution for when the user > > doesnt select anything from the list? > > Also, how did you manage to parse the id of the selected option along > > with the form values? Mine is a belongs_to association and so i am > > using model_auto_completer for now. I hope you can help me with this. > > Here is my post on this > >http://groups.google.co.in/group/rubyonrails-talk/browse_thread/threa... > > > On Jul 20, 12:46 am, Sandeep Gudibanda <rails-mailing-l...@andreas- > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---