bootstrap_form
bootstrap_form copied to clipboard
Allow additional custom markup to text_fields and other inputs
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>
:+1: This would really help with custom bootstrap layouts and plugins that require to have some custom markup.
:+1: For more complex form-groups this would be great.
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.