Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form inside table or table inside form, which one is the right for valid Twitter Bootstrap markup?

I'm working on a template based on Twitter Bootstrap and I have a doubt as title says: Form inside table or table inside form, which one is the right for valid Twitter Bootstrap markup? Are both valid?

First markup:

<form id="fabForm" method="post">
    <div class="form-group">
        <div class="table-responsive">
            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th></th>
                        <th>Col Title</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="fabLinkChoice[]" value="1">
                                </label>
                            </div>
                        </td>
                        <td>Dist1</td>                           
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <button type="submit" class="btn btn-primary" disabled="" id="btnAgregarSelFabricante"><i class="fa fa-save"></i> Add</button>
    </div>
</form>

Second markup:

        <div class="table-responsive">
            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th></th>
                        <th>Col Title</th>
                    </tr>
                </thead>
                <tbody>
                     <form id="fabForm" method="post">
                         <div class="form-group">
                             <tr>
                                  <td>
                                      <div class="checkbox">
                                           <label>
                                               <input type="checkbox" name="fabLinkChoice[]" value="1">
                                           </label>
                                     </div>
                                 </td>
                                 <td>Dist1</td>                           
                             </tr>
                             <tr>
                                 <td colspan="2">
                                     <button type="submit" class="btn btn-primary" disabled="" id="btnAgregarSelFabricante"><i class="fa fa-save"></i> Add</button> 
                                 </td>
                             </tr>
                        </div>
                    </form>
               </tbody>
            </table>
        </div>
    </div>
<div>

NOTE: my doubt has a origin on this code. There you'll notice the code of the first example and also it's on a Bootstrap Modal, but I can't get it look fine. This is what I see on Chrome:

enter image description here

And I don't know if I'm missing something in my markup. Around why I'm using tables is because is a tabular data and I think this is the right or I'm wrong?

like image 300
ReynierPM Avatar asked Jan 05 '15 02:01

ReynierPM


1 Answers

The permitted contents of a tbody tag are zero or more tr tags, so your second example is not valid HTML.

You could move your form inside a table cell, but more commonly you will see a table inside a form instead of vice versa.

It also appears from your limited examples that you may be using a table for layout purposes, which I would urge you to reconsider.

like image 154
Michael Petito Avatar answered Nov 09 '22 04:11

Michael Petito