Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a similar issue: I wanted to have a partial in a <code>has_many</code>/<code>belongs_to</code> or <code>has_and_belongs_to_many</code> association which would use <strong>checkboxes (checkbox group)</strong> instead of the default form widget.</p> <p>I have made an extension <em>(= custom view partial)</em> to <code>rails_admin</code> which allows to easily use checkbox group widget for the <em>related models</em>. </p> <p><strong>It is not exactly your use case</strong> <em>(you have a kind of enumeration checkbox group)</em>, but you could take inspiration from my template, <em>like all templates in <code>rails_admin</code>, even this mine is in HAML</em> :</p> <pre><code>- selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv - n = 3 - data = [] - all_values.sort {|x, y| x[0] &lt;=&gt; y[0] }.each_with_index do |item, index| - (0..(n-1)).each do |p| - data[p] ||= [] - data[p] &lt;&lt; item if index % n == p - data.each_with_index do |slice, c| %div{:class =&gt; [:column, "col-#{c}"]} - slice.each do |item| %div.checkbox_field = check_box_tag "#{form.dom_name(field)}", item[1], selected_ids.include?(item[1]), {:id =&gt; "#{field.method_name}_#{item[1]}"} %label{:for =&gt; "#{field.method_name}_#{item[1]}"} = item[0] </code></pre> <p>Other solution would be to use the <em>default <code>rails_admin</code> enumeration feature</em> (<a href="https://github.com/Juicymo/rails_admin/wiki/Enumeration" rel="nofollow">https://github.com/Juicymo/rails_admin/wiki/Enumeration</a>) and just <em>change it's partial template</em> to use checkboxes instead of adding a custom contant and forms.</p> <p>In case of interest the template and the <code>rails_admin</code> checkbox groups association widget extension is open-sourced on <em>GitHub</em> at: <a href="https://github.com/Juicymo/rails_admin/blob/master/app/views/rails_admin/main/_form_checkboxes_multiselect.html.haml" rel="nofollow">https://github.com/Juicymo/rails_admin/blob/master/app/views/rails_admin/main/_form_checkboxes_multiselect.html.haml</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload