bootstrap-ruby / bootstrap_form

Official repository of the bootstrap_form gem, a Rails form builder that makes it super easy to create beautiful-looking forms using Bootstrap 5.
MIT License
1.64k stars 352 forks source link

Allow additional custom markup to text_fields and other inputs #226

Open fabn opened 9 years ago

fabn commented 9 years ago

Currently the gem allows to insert custom markup using a form_group helper with this syntax

<!-- Radio buttons -->
<%= f.form_group :type, label: {text: 'Type'} do %>
  <%= f.radio_button :type, type_1, inline: true, label: type_1.titleize %>
  <%= f.radio_button :type, type_2, inline: true, label: type_2.titleize %>
<% end %>

<!-- Country selector -->
<%= f.form_group :country_code, label: {text: 'Country'} do %>
    <%= f.country_select :country_code, {include_blank: true}, class: 'form-control' -%>
<% end %>

Text inputs (and also other "native" inputs) won't accept a block, i.e.

<%= f.text_field :title %>

produces this HTML

<div class="form-group">
  <label class="control-label col-sm-2 required" for="item_title">Title</label>
  <div class="col-sm-10">
    <input class="form-control" type="text" name="item[title]" id="item_title" />
  </div>
</div>

It would be nice and useful to build complex forms to have this

<%= f.text_field :title do %>
  <div class="anything">Foo bar</div>
<%- end -%>

to get this HTML

<div class="form-group">
  <label class="control-label col-sm-2 required" for="item_title">Title</label>
  <div class="col-sm-10">
    <input class="form-control" type="text" name="item[title]" id="item_title" />
    <!-- Block output goes here -->
    <div class="anything">Foo bar</div>
  </div>
</div>
jvanbaarsen commented 9 years ago

:+1: This would really help with custom bootstrap layouts and plugins that require to have some custom markup.

lukasnagl commented 9 years ago

:+1: For more complex form-groups this would be great.

NeMO84 commented 9 years ago

Yes this would be great. I am running into this limitation when trying to custom markup radio buttons and checkboxes.

Update: It turns out that check boxes support this already: https://github.com/bootstrap-ruby/rails-bootstrap-forms/blob/master/lib/bootstrap_form/form_builder.rb#L101. I suppose the same approach can be take to implement it for radio buttons.