Skip to content

Bootstrap Switch Checkbox

Stella Rouzi edited this page Feb 6, 2018 · 7 revisions

Bootstrap Switch Checkbox

http://www.bootstrap-switch.org/

Usage:

Insert a check_box_tag and pass:

  • the class switch-checkbox, that is to make the checkbox look like a switch button
  • the variable url, that is the path to which the switch should redirect to when toggled. Do not include in the url the new value that is being set (the value is either true or false and will be set automatically by the state of the switch in the js code in https://github.com/openSUSE/osem/blob/master/app/assets/javascripts/osem-switch.js)
  • the variable method, that is the method with which the path is processed)

Eg. the following code produces a switch checkbox for the model event and changes the attribute require_registration

= check_box_tag @conference.short_title, @event.id, @event.require_registration, method: :patch, url: "/admin/conferences/#{@conference.short_title}/program/events/#{@event.id}?event[require_registration]=", class: 'switch-checkbox', data: { size: 'small', off_color: 'warning', on_text: 'Yes', off_text: 'No' }

Which will look like this, when require_registration is true:

switch-checkbox-on

And like this when require_registration is false:

switch-checkbox-off