Forum: Ruby on Rails observer_field - select form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7c5d3779a96a815f303de322e479fa38?d=identicon&s=25 Achille Pinson (chil)
on 2007-06-03 14:26
I want to load a form when a "select form" is changed. I have done this
but it doesn't work( i do not have an error but nothing change when i
change the select list):

in the view:
<code><% form_tag :action => 'update', :id => @cour do %>

<!-- we choose the type of document (which will determine the form to
include) -->
<p><label for="type_article">Choissisez le type de votre
article:</label><br/>
<%= select :cour, :type_article, {"cours"=>"c",
"exercice"=>"ex"},:include_blank=>true %>

<!-- we observe the select list -->
<%= observe_field 'type_article',
          :update => "formulaire",
          :url=>{:action=>'generation_form'},
          :with=>"'type_article=' + escape(value)",
          %>

<div id="formulaire">-</div>

<%= submit_tag 'Edit' %>
<% end %></code>

In the controller:
<code>def generation_form
    type_article = params[:type_article]
    if type_article == "ex"
    render :partial => "formex"
    else
    render :partial => "formart"
    end
  end</code>

the partial _formex:
<code>(formualaire exo)
<p><label for="cour_content">Contenu</label><br/>
<%= text_area 'cour', 'content'  %></p></code>

thanks
7c5d3779a96a815f303de322e479fa38?d=identicon&s=25 Achille Pinson (chil)
on 2007-06-05 13:51
I found my mistake: wrong name of field.
=> <%= observe_field 'cour_type_article', instead of <%= observe_field
'type_article',

But I still have two problems with the result:
-The form is updated when the mouse is over a type of document and would
like to updated it when the user clic on the field.
-Without AJAX in "edit mode" the field were filled by the data already
saved. Now the fields are blank when the form is updated by AJAX.

Thanks
This topic is locked and can not be replied to.