Search code examples
ruby-on-railsruby-on-rails-3formtastic

Formtastic form doesn't recognize text area added with javascript


I have a form which I'm dynamically adding textareas. The form comes this way:

 <%= semantic_form_for :requisito, :url => update_requisitos_tramites_path, :html =>{ :id => "form_edit_req" } do |f| %>
 ...
<% end %>

When some button is clicked, some function is triggered and adds inside the form the next code:

<textarea rows="3"  class="textarea-obs" name="requisito[observacion]">¿Por qué?</textarea>

and it gets rendered as expected (and the code is in the right place, I checked with the chrome's js console.)

I understand that the input type :text in a form gets converted to a textarea with some id and class but also with a name like model[attribute] for getting the value from the params in the controller like:

params[:model][:attribute]

or in my case:

params[:requisito][:observacion]

but I'm printing the params in the server's log and not value is stored with those symbols. Any ideas?


Solution

  • I didn't solved the recognition problem, just changed the code, so I wrote the textarea in the view but hidden. The javascript was for showing and hiding it, and if you write the name the way I said, it works perfectly! I think was the fact that I was adding the text area dynamically.