Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional custom markup to text_fields and other inputs #226

Open
fabn opened this issue May 12, 2015 · 3 comments
Open

Allow additional custom markup to text_fields and other inputs #226

fabn opened this issue May 12, 2015 · 3 comments

Comments

@fabn
Copy link

fabn commented May 12, 2015

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
Copy link

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

@lukasnagl
Copy link

👍 For more complex form-groups this would be great.

@NeMO84
Copy link

NeMO84 commented Sep 10, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants