Question

I want to span a form across tabs so a single submit button submits edits no matter which tab was edited. Here is what I've tried that isn't working. I'm using Rails 4, haml, simple_form, and Bootstrap 3.

%ul.nav.nav-tabs
  %li.active
  %a{"data-toggle" => "tab", href: "#tab_1"} Tab 1
  %li
  %a{"data-toggle" => "tab", href: "#tab_2"} Tab 2
.tab-content
  =simple_form_for @account do |f|
    #tab_1.tab-pane.active
    =f.input :account_number
    =f.input :name
    #tab_2.tab-pane
    =f.input :account_datails_1
    =f.input :account_deatils_2
    .form-actions
      = f.submit nil, :class => 'btn btn-primary'
      = link_to 'Cancel', accounts_path, :class => 'btn'

I know I can place a separate form on each tab, but I want to separate out details on other tabs with a single submit. Is this possible?

Was it helpful?

Solution

I've run into this before and all I had to do was this (granted this might not be ideal practice but did work for me):

=simple_form_for @account do |f|
  %ul.nav.nav-tabs
    %li.active
    %a{"data-toggle" => "tab", href: "#tab_1"} Tab 1
    %li
    %a{"data-toggle" => "tab", href: "#tab_2"} Tab 2
  .tab_content  
    #tab_1.tab-pane.in.active
    =f.input :account_number
    =f.input :name
    #tab_2.tab-pane
    =f.input :account_datails_1
    =f.input :account_deatils_2
  .form-actions
    = f.submit nil, :class => 'btn btn-primary'
    = link_to 'Cancel', accounts_path, :class => 'btn'

In essence, just move the '= simple_form' expression above the .tab_content

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top