Bootstrap: Can you make it more friendly with Ruby on Rails?

Created on 6 May 2017  路  2Comments  路  Source: twbs/bootstrap

When creating forms, Rails will wrap the input fields in divs with class field_with_errors. However, this breaks the display of the input group fields and shrinks them or changes the size, etc. Can you please make the fields display properly even with these wrappers? For example, the HAML

    .form-group
      =cf.label :revenue
      .input-group
        .input-group-addon $
        =cf.number_field :revenue, class: 'form-control'

generates

<div class="form-group">
            <label for="deal_company_attributes_revenue">Revenue</label>
            <div class="input-group">
              <div class="input-group-addon">$</div>
              <input class="form-control" type="number" name="deal[company_attributes][revenue]" id="deal_company_attributes_revenue">
            </div>
          </div>

and when there is an error generates

<div class="form-group">
            <div class="field_with_errors"><label for="deal_company_attributes_revenue">Revenue</label></div>
            <div class="input-group">
              <div class="input-group-addon">$</div>
              <div class="field_with_errors"><input class="form-control" type="number" value="" name="deal[company_attributes][revenue]" id="deal_company_attributes_revenue"></div>
            </div>
          </div>

This changes the field width display to be shorter, so short there isn't enough room to see the numbers.

I'm using https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css

css v4

Most helpful comment

Are you sure this behaviour you are writing about isn't possible to opt out?

https://coderwall.com/p/s-zwrg/remove-rails-field_with_errors-wrapper

All 2 comments

Are you sure this behaviour you are writing about isn't possible to opt out?

https://coderwall.com/p/s-zwrg/remove-rails-field_with_errors-wrapper

No planned changes here鈥攚e kinda need the markup we use. Sounds like this can be opted out of though given @rafalp's comment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MrCsabaToth picture MrCsabaToth  路  3Comments

devdelimited picture devdelimited  路  3Comments

matsava picture matsava  路  3Comments

bellwood picture bellwood  路  3Comments

kamov picture kamov  路  3Comments