I am working on adding a data attribute into the item_wrapper_tag for a given input, based on values entered in the input. For example, I have the input referencing a custom component as follows:
= f.input :cat_and_bear,
hide_if: { select_list: 'dog' },
required: true
I have a custom component created, it does run, I can access input_options and get the value of `hide_if`. This code is based off of
this issue, which was the closest thing I was able to find to what I was trying to do.
module SimpleFormComponents
module HideFieldComponent
def hide_if(wrapper_options = nil)
html_options_for(:wrapper, wrapper_options).tap do |options|
options[:data_hide_contingent_field] = input_options[:hide_if].keys.first
options[:data_hide_if_values] = input_options[:hide_if].values.first
end
end
end
end
I would like to add the two data attributes to the item_wrapper_tag. Currently, the output looks like this:
<div class="input string required cat_and_bear">
"{:data_hide_contingent_field=>:select_list, :data_hide_unless_values=>"dog"}"
<label class="string required" for="cat_and_bear">Cat and Bear<span class="label-required">(required)</span></label>
<input class="string required" required="required" aria-required="true" type="text" name="animal_form[cat_and_bear]" id="cat_and_bear">
</div>
I have been looking for how to access the wrapper to add to the html_options, but I have not been able to figure it out. Can someone help or point me to resources where this has been discussed?
Thanks,
Christine