Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use bootstrap form layout without actually using <form>?

We need the formatting and layout that comes with using something like the following but we don't want the traditional HTML form (we use ajax, javascript to pull/set data on our controls). The problem is when you hit 'enter' the page assumes you are submitting a form, probably because there is form tag (but there was no submit button, so maybe it is defaulting to one of the buttons, but that's a different story):

<form role="form" class="form-horizontal">      
        <legend>Product Header Information</legend>
        <div class="form-group form-group-sm">
            <label for="pid" class="control-label field_name2 col-xs-4 col-sm-4 col-md-3">Product ID:</label>
            <div class="col-xs-8 col-sm-4 col-md-4">
                    <input class="form-control" id="pid" />
            </div>
        </div>
.....
</form>
like image 995
AlpharettaTechy Avatar asked Mar 04 '15 13:03

AlpharettaTechy


People also ask

What is the default Bootstrap form layout?

Bootstrap provides three types of form layouts: Vertical form (this is default) Horizontal form. Inline form.

What is form inline in Bootstrap?

Displaying Bootstrap forms inline By default, form controls will be displayed one below the other. However, you can make your form labels and inputs appear inline, horizontally, by applying the form-inline class. (Note that it will appear inline only in viewports that are at least 576px wide.)


2 Answers

Here is the answer, simply replace "form" with "div", that seems to work great in firefox, IE & Chrome. It does makes sense.. I need css classes, I use css classes, who cares on what tag?

<div class="form-horizontal">      
        <legend>Product Header Information</legend>
        <div class="form-group form-group-sm">
            <label for="pid" class="control-label field_name2 col-xs-4 col-sm-4 col-md-3">Product ID:</label>
            <div class="col-xs-8 col-sm-4 col-md-4">
                    <input class="form-control" id="pid" />
            </div>
        </div>
.....
</div>
like image 127
AlpharettaTechy Avatar answered Oct 18 '22 12:10

AlpharettaTechy


Using form is the right way. In order to prevent the form from refreshing the page on submit you can use jQuery:

("form").on("submit", function () { /*your ajax*/ return false; });

like image 28
Timur Osadchiy Avatar answered Oct 18 '22 13:10

Timur Osadchiy