views:

102

answers:

1

I have some saved text in my create controller. If it's not stressful, I'd like it to populate a textarea on the page with the saved text along with displaying the error message fields (which is what's already happening). I've used things like replace_html before, but I don't know if there's an easy way to get to textarea or text field IDs and just replace the value of the text. For now I'm just going to do some javascript but it would be nice to know the rails shortcut.

edit: I wasn't in the right mindset because this app uses extjs and was trying to figure out how to do it this way. The text box is actually an ext status bar (same as here : http://www.extjs.com/deploy/dev/examples/statusbar/statusbar-demo.html ) which doesn't get created until the page is finished loading. When I try to enter commnands like the first poster suggested, I get "setvalue is not a function". Playing with firebug on the page I can get it to set the value after loading by using (whatever method to get it through ext or scriptaculous).value = "lol" but none of the page update things work with this.

A: 

In your render do |page| you can use the "page <<" to pass inline js so that you can invoke setValue on your texfield element

prototype:

page << "$('texfield_id').setValue('lol');"

page << "$('texfield_id').setValue('#{your_value}');"

# if you like to use rails-like helpers (wich I usually do not) this would also work
page[:textfield_id].setValue your_value 

jquery:

page << "$('#tf_id').val('lol');"

enjoy

makevoid
Thanks for the comment, durr. I made an edit because my situation is a little more complicated.
Stacia