Class: BootstrapForm::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/chaltron/form_builder/bootstrap_form.rb

Instance Method Summary collapse

Instance Method Details

#role_select(opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/chaltron/form_builder/bootstrap_form.rb', line 4

def role_select(opts = {})
  collection = Chaltron.roles.map { |role| [role, I18n.translate("roles.#{role}")] }
  checked = @object.nil?? false : @object.roles
  html = inputs_collection(:roles, collection, :first, :last, checked: checked) do |name, value, options|
    options[:multiple] = true
    options[:inline] = opts.fetch(:inline, true)

    if value == opts[:disabled]
      options[:disabled] = true
      options[:checked] = true
    end
    check_box(name, options, value, nil)
  end

  hidden = opts[:disabled] || ''
  hidden_field(:roles, { value: hidden, multiple: true }).concat(html)
end