Form Question

I have a custom form builder that output form elements as

  • tags.

    So

    <%= form.input :first_name%>
    <%= form.input :last_name%>

    generates like…

    1. first_name_label - first_name_text
    2. last_name_label - last_name_text

    I want to provide a link next to the text fields and I do that like…

    <%= form.input :first_name%>
    <%= form.input :last_name%>

    <%= link_to_function “clear”, :id => , “this.up(‘li’).remove()” %>

    This works fine but the link is located outside of the

  • tag which
    causes the formatting to be weired. How can I generate this link and
    position it within the
  • tag it is supposed to remove? I think the
    answer might be very simple, i am just not clear about how to move an
    elements while creating it.
  • elements while creating it.
    I would recommend you do it either as:

    <%= form.input :last_name, :links => [{:name => “clear”, :function =>
    “this.up(‘li’).remove()”}] %>

    or:

    <% form.input :last_name do %>
    <%= link_to_function “clear”, :id => , “this.up(‘li’).remove()” %>
    <% end %>

    Either way you’re going to have to amend your custom form builder. Your
    form builder is already outputting the

  • . If you’re doing it the
    second
    way (which I’d recommend as it’s more flexible) remember you can’t have
    <%=
    with do/end so you have to use concat to output the content if
    block_given?
    (within your input method).

    Alternatively, you could do it with jQuery or something similar - give
    the
    link a class and then have a DOM ready event move any items with that
    class
    within the previous sibling.

    Cheers,

    Andy