How to have just one form on several Twitter Bootstrap tabs?

前端 未结 2 544
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 22:26

How to have one form one several Twitter Bootstrap tabs?

相关标签:
2条回答
  • 2021-02-05 22:49

    What's wrong of having one <form> that wraps everything up?

    <form id="personal-data" class="form-horizontal" method="POST" action="#">
    
    <div class="tabbable">
      <ul class="nav nav-tabs">
        <li class="active">
          <a href="#1" data-toggle="tab">Tab1</a>
        </li>
        <li>
          <a href="#2" data-toggle="tab">Tab2</a>
        </li>            
      </ul>
      <div class="tab-content">
        <div class="tab-pane" id="1">      
          ...
        </div>
        <div class="tab-pane" id="2">
          <!-- form controls to be continued here -->
          <p>Howdy, I'm in Section 2.</p>
        </div>            
      </div>
    </div>
    
    </form>
    

    are you submitting tab by tab or once on the last tab?

    if one-by-one (for exemple, validation), simply use $.post to send data back and forward on-the-fly (in other words, make ajax calls).

    0 讨论(0)
  • 2021-02-05 22:55

    I just bumped into the same problem, if you want to submit once in the last tab, I assume there's a button somewhere to move beetwen tabs. By default clicking those buttons will trigger the POST request. To prevent this add following line to your button click funciton:

    event.preventDefault();
    
    0 讨论(0)
提交回复
热议问题