This question is really two questions.
Active_admin
uses formtastic to render forms, so I'm going to ask in the context of formtastic. How would I create a button that selects all the checkboxes on the page? I could do it using JavaScript, but I'm unsure of how to do this in formtastic.Set collection based on select value. I have a drop down menu that let's people choose from a list of "Courses". Students are enrolled in courses, so I want to be able to display a checkbox list of student enrolled on the course. Ie: The list of students will change if the user selects a different course.
has_and_belongs_to_many :students
has_and_belongs_to_many :courses
Formtastic does not have an easy solution for a "select all" checkbox, if you are using JQUERY you can do this
In your student.rb model add
attr_accessor :select_all_courses
f.inputs "Courses" do
f.input :select_all_courses, :as => :boolean, :label => 'SELECT ALL', :input_html => {:onclick => "jQuery.each( $('.student_courses_checkboxes'), function() { this.checked = $('.all_selector')[0].checked });", :class => "all_selector"}
f.input :courses, :as => :check_boxes, :collection => @courses, :input_html => {:class => 'student_courses_checkboxes'}
end
The best you can do in active admin with formtastic is:
In your course form
f.input :students, :as => :check_boxes, :collection => @students
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With