Hi there, I''m going to start with an example: <% form_for(@post) do |f| %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <% end %> Generates: <form action="..."> <p> <label for="post_title">Title</label><br /> <input id="post_title" name="post[title]" size="30" type="text" value="foobar" /> </p> </form> Is there any way to get the input id as a string out of the form (f) object? The example is quite simple, but if there are nested forms there are id''s like thread_posts_attributes_0_title and I need that id to modify the value with JavaScript. Hope there''s a solution. Thanks! -- Posted via http://www.ruby-forum.com/.
You could just specify the id yourself, rather than trying to read/replicate the auto-generated one, is that an option? That way you know for sure what it''s going to be called, which will make it easier to refer to in your JS. If so then use the :id option and make sure you give it a unique id, like "post_#{post.id}_name" or something. -- Posted via http://www.ruby-forum.com/.
Max Williams wrote:> You could just specify the id yourself, rather than trying to > read/replicate the auto-generated one, is that an option? That way you > know for sure what it''s going to be called, which will make it easier to > refer to in your JS. > > If so then use the :id option and make sure you give it a unique id, > like "post_#{post.id}_name" or something.That is indeed an option. Thank you very much! -- Posted via http://www.ruby-forum.com/.