I’m using a javascript function to insert html code into my page
(following the Railscast on nested models)
The function that inserts the javascript is this:
function add_result(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp(“new_” + association, “g”);
var linkrow = $(link).up(“tr”);
linkrow.insert({
after: content.replace(regexp, new_id) });
}
And this is the html.erb that is inserted:
<% for c in @picture_fields %>
<% if c == "intervention" %>
<tr class="pictureclass">
<td class="name"><%=t 'form.results.picture.'+c%></td>
<td><%= f.radio_button c,
t(‘form.results.picture.interventionoptions.option1’)%><%=t
‘form.results.picture.interventionoptions.option1’%><%= f.radio_button
c, t(‘form.results.picture.interventionoptions.option2’)%><%=t
‘form.results.picture.interventionoptions.option2’%><%= f.radio_button
c, t(‘form.results.picture.interventionoptions.option3’)%><%=t
‘form.results.picture.interventionoptions.option3’%>
<% elsif c == "couchetype" %>
<tr class="pictureclass">
<td class="name"><%=t 'form.results.picture.'+c%></td>
<td><%= f.text_field :selected_couchetypes, :readonly=>true %></
td>
link_to( image_tag(‘more.png’, :border=>0,
:id=>“new_results_pictures_results_pictures_couchetype”),
{:controller=>“thesaurus”, :action=>“list”,
:id=>“new_results_pictures_results_pictures_couchetype”},
{ :popup=>[‘thesaurus’,
‘height=800,width=750,location=no,scrollbars=yes’]}) %>
<%else %>
<tr class="pictureclass"><td></td><td ></td></tr>
<tr class="pictureclass">
<td class="name"><%=t 'form.results.picture.'+c%></td>
<td><%= f.text_field c, :class=>"number"%></td>
</tr>
<% end %>
<% end %>
f.hidden_field :_destroy %><%= link_to_function
t(‘form.results.picture.destroy’), “remove_fields(this,
‘.pictureclass’)”%>
When the html is inserted, there is a size=“30” attribute for the text
input field:
But I have no idea how it got there. Any ideas?