2

I have a form with a few fields that need to be inline. Bootstrap is not letting me do this, it renders the form fields on a entire line. Also, I would like the labels to be next to the field.

Is it feasible to wrap a subset of fields in a form tag that is set to form-inline, and how do I get the form fields not to break on their own lines. Here is what I am trying to achieve:

enter image description here

Here is what I've tried:

<div class="form-group">
    Zipcode <input type="text" data-bind="value: Zipcode" class="form-control"> 
    Response Time <input type="text" data-bind="value: ResponseNumber" class="form-control"> <select data-bind="options: ResponseUnits" />
</div>'

Also, I have not wrapped the form in <form> because I am using <form> to wrap a file dropzone. I am using knockout and ajax, so I don't need to use forms (unless they are required for bootstrap).

4
  • 1
    Where's you code? What have you tried? Commented Dec 4, 2015 at 17:23
  • getbootstrap.com/css/#forms-inline Commented Dec 4, 2015 at 17:27
  • You forgot to include your CSS. Commented Dec 4, 2015 at 17:32
  • There is no CSS and my superiors don't like me to use CSS unless I have a very good reason. Commented Dec 4, 2015 at 17:45

1 Answer 1

2

looks like from your example you are more after a horizontal style form. use form groups.

https://jsfiddle.net/whxf78zw/1/

<form class="form-horizontal" role="form">
  <div class="form-group">
    <label class="control-label col-sm-2" for="email">Zipcode:</label>
    <div class="col-sm-6">
      <input type="text" class="form-control" id="zipcode" placeholder="Enter zip">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="responseTime">Response Time:</label>
    <div class="col-sm-3"> 
      <input type="number" class="form-control" id="responseTime" placeholder="Enter response time">
    </div>
   <div class="col-sm-3"> 
        <select class="form-control">
            <option>Hours</option>
            <option>Days</option>
            <option>Weeks</option>
            <option>Months</option>
            <option>Years</option>
          </select>

      </div>
    </div>

</form> 
Sign up to request clarification or add additional context in comments.

6 Comments

Note that everything renders block unless the screen is wide enough to hit the small breakpoint.
(I'd probably change your column classes to col-xs-*.)
Thanks for the answer. I have an element in the form that uses dropzonejs, and it requires the element to be wrapped in a form tag. So, if I do it this way I will have a nested form element, which I understand to be bad. I see I can replace the form element in your example with a div tag, but is that kosher?
yep you can do that, (change form to div) I do that a lot when I'm making .net aspx pages because the whole thing is in a form tag.
How can I control the indentation of the labels? They are too far to the right.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.