Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery.Tokeninput with dynamic nested forms in rails 3.0.9
    primarykey
    data
    text
    <p>im trying to use the jquery Tokeninput plugin for autocomplete pouporse in my form application.</p> <p>the thing is, in my java script the context ID is dinamically generate, so i dont know how to specify it to work, and even if i use the paremeter :id in the view field it is not identifyed.</p> <p>I tryed to use this with a single not dynamic field and worked just fine. The problem is with the edit view. When i come to edit, every field shows all results for that item.</p> <p>So if i have 3 field, the 3 display all the 3 itens.</p> <p>my views involved are</p> <p>/views/comps/new.html.erb</p> <pre><code>&lt;h1&gt;Cadastrar nova composicao:&lt;/h1&gt; &lt;%= form_for(@comp) do |f| %&gt; &lt;%= render 'fields', :f =&gt; f %&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Salvar" %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>/views/comps/_fields.html.erb</p> <pre><code>&lt;%= render 'shared/error_messages', :object =&gt; f.object %&gt; &lt;br&gt; &lt;table class="field"&gt; &lt;tr&gt; &lt;td&gt;&lt;%= f.label :nome, "Nome" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.text_field :nome %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.label :projetoorigem_id, "Projeto de origem" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.text_field :projetoorigem_id %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;%= f.label :user_id, "Autor" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.text_field :user_id %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.label :unidade_id, "Unidade" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.text_field :unidade_id %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;%= f.label :tipo, "Tipo" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.text_field :tipo %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.label :valor, "Valor" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= f.text_field :valor %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div id="add" class="none"&gt; Insumos da composicao &lt;/br&gt; &lt;ol&gt; &lt;div&gt; &lt;%= link_to_add_fields (image_tag "add.jpg"), f, :insumos_comp_rels %&gt; &lt;%= f.fields_for :insumos_comp_rels do |builder| %&gt; &lt;%= render "insumos_comp_rel_fields", :f =&gt; builder %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/ol&gt; </code></pre> <p>/views/comps/_insumos_comp_rel_fields.html/erb</p> <pre><code>&lt;li class="fields"&gt; &lt;%= link_to_remove_fields (image_tag "delete.jpg"), f %&gt; &lt;%= f.text_field :insumo_id, :id =&gt; "insumo_id" %&gt; &lt;%= f.collection_select(:clifor_id, Clifor.all, :id, :nome_fantasia)%&gt; &lt;%= f.collection_select(:modelo_id, Modelo.all, :id, :nome)%&gt; &lt;%= f.collection_select(:unidade_id, Unidade.all, :id, :simbolo)%&gt; &lt;%= f.text_field :valor %&gt; &lt;%= f.text_field :quantidade %&gt; &lt;/li&gt; </code></pre> <p>The jQuery file is:</p> <p>/application.js</p> <pre><code>function remove_fields(link) { $(link).prev("input[type=hidden]").val("1"); $(link).closest(".fields").hide(); } function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g") $(link).parent().after(content.replace(regexp, new_id)); } $(function(){ $("#insumo_id", $(this)).tokenInput("/insumos.json", { propertyToSearch: "nome", tokenLimit: 1, theme: "facebook", searchingText: "Procurando...", hintText: "Digite o que deseja procurar" }); }) </code></pre> <p>Any ideas would be very apreciataded.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload