OK .. I managed to somehow solve this, not sure if this is the best alternative, but I send it like this if someone needs it in the future, at least he has something to start with.
I went with creating a βregularβ form using simpleform and then using jQuery to move the internal input fields (which were created regularly) next to the radio buttons.
Add jQuery support to your rails application:
- add
gem "jquery-rails" to your gemfile bundle installrails generate jquery:install
The form I used (regular simple form):
Pay attention to the class that is connected to the switches and identifiers attached to the input fields. I will use it later to move items.
<%= simple_form_for @client, url: 'update_payment_data' do |f| %> <%= f.input :payment_type, label: t('account.update_payment_method.title'), input_html: { class: 'payment_method_options' }, collection: [ [t('account.update_payment_method.sum_based.title'), :amount], [t('account.update_payment_method.days_in_month_based.title'), :days_in_month], [t('account.update_payment_method.optout.title'), :optput] ], as: :radio_buttons %> <%= f.input :payment_amount, label: "Payment amount threshold", input_html: { id: 'payment_amount_box' } %> <%= f.input :payment_days_in_month, label: "Payment days in month", input_html: { id: 'payment_days_in_month_box' } %> <%= f.button :submit, t('account.update_payment_method.update') %> <% end %>
On the same page is the jQuery code:
<script> $(document).ready(function() { var amount_box = $("#payment_amount_box"); var amount_box_parent = amount_box.parent(); amount_box.detach().appendTo($(".payment_method_options:eq(0)").parent()); amount_box_parent.remove(); var dim_box = $("#payment_days_in_month_box"); var dim_box_parent = dim_box.parent(); dim_box.detach().appendTo($(".payment_method_options:eq(2)").parent()); dim_box_parent.remove(); }); </script>
I think this is pretty understandable, it just looks for what will be the internal input fields (by id) and moves them to the appropriate place under the span , which simpleform creates for each switch.
I had to play a little with css to make it look the way I wanted (e.g. display:block ), but this is more or less.
Hope this helps .. Zach