views:

14

answers:

1

Hi,

I am trying to set a default value for a text field used for a search, which uses the observe method. Here's what I got which works.

<% form_tag('javascript:void(0)') do %>
    <%= text_field_tag 'phrase', nil, {:onfocus => "$('results').show();", :onblur => "$('results').hide();"} %>
    <%= observe_field :phrase,
      :frequency => 0.5,  
      :update => 'results',
      :url => {:controller => :profiles, :action => 'search', :only_path => false },
      :with => "'phrase=' + encodeURIComponent(value)" %>
 <% end %>

This works fine, but obviously the value is nil.

Now if I add in the value like so:

<% form_tag('javascript:void(0)') do %>
    <%= text_field_tag 'phrase', :value => 'test', {:onfocus => "$('results').show();", :onblur => "$('results').hide();"} %>
    <%= observe_field :phrase,
      :frequency => 0.5,  
      :update => 'results',
      :url => {:controller => :profiles, :action => 'search', :only_path => false },
      :with => "'phrase=' + encodeURIComponent(value)" %>
 <% end %>

An exception is thrown.

Any idea on how I can get a default value for this text field?

Thank you.

A: 

Do not use :value => 'test', simply use 'test':

<%= text_field_tag 'phrase', 'test' %>

The format you tried to use is for text_field helper that is usually coming from a model, text_field_tag does not typically come from a model.

fflyer05
cool thanks. weird though.. in firefox the value doesn't display, but in chrome and ie it does.
Brian
never mind. its works thank you
Brian