Nesting Inputs Inside Label Tag

31 views
Skip to first unread message

Chris Kiklas

unread,
Dec 23, 2015, 6:03:15 AM12/23/15
to SimpleForm

I'm using Rails 4 and Simple_Form for an application, and for the front end layout I have to implement, I need to be able to have the input tag inside a label tag. The output needs to look like this:

<label class="input string optional profile_first_name">
    <input class="string optional" type="text" value="" name="profile[first_name]" id="profile_first_name">
</label>

I tried creating a custom wrapper that looked like this:

config.wrappers :custom_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  b.use :html5
  b.use :placeholder
  b.optional :maxlength
  b.optional :pattern
  b.optional :min_max
  b.optional :readonly

  b.wrapper tag: 'label' do |ba|
   ba.use :input
   ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
   ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  end
end

The issue I am running into is that the resulting html is missing the label text that Smart_Form usually generates. I am sure there has to be a way to correctly format the wrapper to display the input inside the label tag and for the label to still display, but I am at a loss. Thanks in advance!

Reply all
Reply to author
Forward
0 new messages