javascript - If you can't nest HTML forms, how can you submit multiple selections? -


so example, have table checkbox each row. now, added in functionality able delete multiple selected rows using built in rails form helper. problem is, need able 'disable selected' , 'enable selected' rows well.

 <%= form_tag sccm_destroy_multiple_url , method: :delete %>  .... table rows , data  <%= check_box_tag "id[]", group.id %>  ... more rows  <%= button_tag "delete selected", type: 'button submit', class: "btn btn-danger",data: {confirm: "are sure want delete these groups?"} %>                            <i class="fa fa-trash-o"></i> delete selected <%end%> <%end%> 

now need put button "disable selected" can't since nesting forms , forms way store multiple checkbox ids i'm aware of...any ideas?

basically rails gets around limitation in html creating arrays , nested hashes name attributes:

<input type="text" name="dogs[0][breed]" value="husky"> <input type="text" name="dogs[1][breed]" value="shiba inu"> 

rails interpret these params as:

"dogs" => {   "0" => {     "breed" => "husky"   },   "1" => {     "breed" => "shiba inu"   }, } 

you use fields_for gives special "scoped" form builder instance:

<%= forms_for(@adaption_agency) |k| %>    <%= f.fields_for(:dogs) |doggy_fields| %>      <%= doggy_fields.text_field :breed %>    <% end %> <% end %> 

in case create update_multiple route , use fields_for array of records.

but consider using ajax instead allow user manipulate several records on same page standard crud actions. lot less complex trying mosh mega actions.

<%= dogs.each |doggy| %>    <%= form_for(doggy), class: 'doggy-form' |f| %>       <%= f.text_input :breed %>    <% end %>    <%= button_to('delete', dog_path(doggy), method: :delete, class: 'doggy-form') %> <% end %> 

note creates forms each type of action.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -