views:

34

answers:

2

I have an observe_field call in my app like this:

  = observe_field "marketSelect", :update => "merchantSelect", :with => "id", :url => { :controller => "markets", :action => "get_merchants" }

That code activates the following action in my markets controller:

@merchants = @market.merchants.sort_by { |merchants| merchants.name }

That code returns a list of every merchant associated with the selected market, and populates them into another selection list.

How can I insert an empty "Select merchant..." along with the merchants?

Thank you

A: 

Hmm.. I found this at http://joshhuckabee.com/rails-observe-field-function-and

observe_field 'text_field_id', 
    {:function => "(value == '') ? 
        $('email_preview').innerHTML = 
             '<em>not entered yet</em>' :
        $('email_preview').innerHTML = 
             value.replace(/\\n/g, '<br/>');", 
      :on => 'keyup'}

The author did this with prototype. He had added a little snippet that will replace carriage returns with HTML line breaks and also set a default value if no text is entered or the field gets cleared out.

Trip
A: 

Thanks for the suggestion. I ended up just building a straight javascript solution.

Kevin Whitaker