Is there a possibility to replace the value of a textfield
within rjs? I am calling a link_to_remote within a form,
to get some data. Now I want to fill in that data in the
existing form. The problem is that I can replace the html,
but I can’t replace the value=“text_i_want_to_change”,
but that is the thing that you see and that is submitted by
elements that it typically finds by their id, less often by their name.
gives you two options: ‘replace’ which will replace the entire contents with a new one, and
which will replace the contents within the but leave the ‘wrapper’ alone. Each
option you could use. Either way, you’re going to have to either put a
unique id on the textfield itself, or wrap it in another element that
unique id. (e.g., <div id=‘unique_identifier>) A lot of Rails
methods call for element name (which is not required to be unique) and
unless you specify otherwise, also use that name as the elements’ id.
can give you a rendered page with lots of elements having the same id.
Result: your RJS will not work. Use Firebug to inspect the DOM.
Easiest option to understand is to wrap the textfield, then use
page.replace_html with a partial that feeds the value you sent back to
controller with link_to_remote as a local.
If you haven’t already picked it up, I strongly recommend Cody F.'s
tutorial. Best $10 bucks you’ll spend learning Rails / Ajax. It’s a PDF
available at O’Reilly and will have you done with this and moving
very short time.