views:

179

answers:

1

Hi All,

I'm trying to build a form field that can either accept a text entry, or select an option from a dropdown. In rails, the autocomplete plugin is close to what I need, except I want the dropdown to be available before the user types anything in the text field. Is there an example of this out there somewhere?

thx for the help,

-C

A: 

I have used this code on a view to select a date or enter a name (I hope you read HAML):

%center
  - form_remote_tag :update => 'filter_counts', :url => { :action => 'name_filter', :controller => 'dictated_exams', :method => :post } do
    Please enter part of a name ('%' is the wildcard character):
    = text_field_tag 'search', nil, :maxlength => 15, :size => 15
    = submit_tag 'Search'
  %b OR
  pick the exam date:
  = calendar_date_select_tag "date", Date.today, :time => false, :valid_date_check => "date < (new Date()).stripTime()" 

  = image_tag "spinner.gif", :align => "absmiddle", :border => 0, :id => "spinner", :style => "display: none;" 

= observe_field :date, :with => :date, :frequency => 1, :url => {:action => 'filter_widget', :controller => 'dictated_exams', :method => :post }, :update => :filter_counts, :before => "Element.show('spinner')", :success => "Element.hide('spinner')"

On the other hand, maybe you're just looking for this: Rails' observe_form method Basically, the question is : do you need to have those two methods of entry in a single form, or can they be separate? If so, you can also watch them separately.

Trevoke