Search code examples
ruby-on-rails-4sprocketsturbolinkstwitter-bootstrap-4bootstrap-4

Can't get styles to dynamic content


I'm facing strange behaviour: bootstrap somewhat works on my pages, but doesn't style my for forms.

I can see that it loads and all because of buttons, flexbox, grid system. However I can't get it to style forms. Here I'm showing dynamic form with the same code as static form on the same page:

enter image description here

The static form is styled correctly, where as dynamic form is just normalized without any styles applied. I think it is connected with sprockets but having hard time trying to figure it out.

Edit:

<div class="col-md-6">
  <%= form_for(@form) do |f| %>
    <%= render partial: 'shared/req_errors', locals: {scope: "req_statuses.fields"} %>

    <div class="form-group">
      <%= f.label t('.dest') %><br>
      <%= f.select :dest, ReqStatus.dests.collect {|c| [t(".#{c}"), c] } %>
    </div>

    <div class="form-group">
      <%= f.label t('.note') %><br>
      <%= f.text_area :note, cols: 40, placeholder: t('.note-placeholder') %>
    </div>

    <div class="form-group">
      <%= f.label t('.copies') %><br>
      <%= f.select :copies, (1..Request::MAX_NUMBER_OF_COPIES) %>
    </div>

    <div class="actions">
      <%= f.submit t('.submit'), class: "btn btn-primary" %>
    </div>

  <% end %>


  <!-- from: http://v4-alpha.getbootstrap.com/components/forms -->

  <form>
    <div class="form-group">
      <label for="exampleInputEmail1">Email address</label>
      <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
      <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
    </div>
    <div class="form-group">
      <label for="exampleInputPassword1">Password</label>
      <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
    </div>
    <div class="form-group">
      <label for="exampleSelect1">Example select</label>
      <select class="form-control" id="exampleSelect1">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
      </select>
    </div>
    <div class="form-group">
      <label for="exampleSelect2">Example multiple select</label>
      <select multiple class="form-control" id="exampleSelect2">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
      </select>
    </div>
    <div class="form-group">
      <label for="exampleTextarea">Example textarea</label>
      <textarea class="form-control" id="exampleTextarea" rows="3"></textarea>
    </div>
    <div class="form-group">
      <label for="exampleInputFile">File input</label>
      <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
      <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
    </div>
    <fieldset class="form-group">
      <legend>Radio buttons</legend>
      <div class="form-check">
        <label class="form-check-label">
          <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios1" value="option1" checked>
          Option one is this and that&mdash;be sure to include why it's great
        </label>
      </div>
      <div class="form-check">
      <label class="form-check-label">
          <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios2" value="option2">
          Option two can be something else and selecting it will deselect option one
        </label>
      </div>
      <div class="form-check disabled">
      <label class="form-check-label">
          <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
          Option three is disabled
        </label>
      </div>
    </fieldset>
    <div class="form-check">
      <label class="form-check-label">
        <input type="checkbox" class="form-check-input">
        Check me out
      </label>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>

</div>

Solution

  • I think you forgot to apply CSS for your dynamic form controls. Try adding form-control class to all of the controls in your form would help.