I have created a custom wrapper for simple_form but I can't seem to find a way to add data attributes to the generated wrapper element. I'm trying to add it to the inner wrapper class called switch.
I want to be able to add it to the wrapper, not in view layer if possible.
config.wrappers :toggle, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |ba|
ba.wrapper :tag => 'div', :class => 'switch' do |box|
box.use :input
end
ba.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
end
end
= form.input :element, :label => t('views.items.attributes.element'), :wrapper => :toggle
Output
<div class="control-group boolean optional">
<label class="boolean optional control-label" for="item_element">Element</label>
<div class="controls">
<div class="switch">
<input name="item[element]" type="hidden" value="0">
<input class="boolean optional" id="item_element" name="item[element]" type="checkbox" value="1">
</div>
</div>
</div>
Desired Output
<div class="control-group boolean optional">
<label class="boolean optional control-label" for="item_element">Element</label>
<div class="controls">
<div class="switch" data-label="blah" data-id="something">
<input name="item[element]" type="hidden" value="0">
<input class="boolean optional" id="item_element" name="item[element]" type="checkbox" value="1">
</div>
</div>
</div>