allow to specify (un)checked values for config boolean

Conflicts:
	app/helpers/admin/configs_helper.rb
This commit is contained in:
wvengen 2014-06-23 23:58:44 +02:00
parent 34e8901d04
commit 9beaac2627

View file

@ -16,8 +16,8 @@ module Admin::ConfigsHelper
config_input_tooltip_options form, key, options[:input_html] config_input_tooltip_options form, key, options[:input_html]
if options[:as] == :boolean if options[:as] == :boolean
options[:input_html][:checked] = 'checked' if options[:input_html].delete(:value) options[:input_html][:checked] = 'checked' if options[:input_html].delete(:value)
options[:checked_value] = true options[:checked_value] = 'true' if options[:checked_value].nil?
options[:unchecked_value] = false options[:unchecked_value] = 'false' if options[:unchecked_value].nil?
elsif options[:collection] or options[:as] == :select elsif options[:collection] or options[:as] == :select
options[:selected] = options[:input_html].delete(:value) options[:selected] = options[:input_html].delete(:value)
return form.input key, options, &block return form.input key, options, &block
@ -36,14 +36,18 @@ module Admin::ConfigsHelper
# @return [String] Form input field for configuration key. # @return [String] Form input field for configuration key.
# @see config_input # @see config_input
# @option options [String] :checked_value Value for boolean when checked (default +true+)
# @option options [String] :unchecked_value Value for boolean when not checked (default +false+)
# @todo find out how to pass +checked_value+ and +unchecked_value+ to +input_field+ # @todo find out how to pass +checked_value+ and +unchecked_value+ to +input_field+
def config_input_field(form, key, options = {}) def config_input_field(form, key, options = {})
return unless @cfg.allowed_key? :key return unless @cfg.allowed_key? :key
config_input_field_options form, key, options config_input_field_options form, key, options
config_input_tooltip_options form, key, options config_input_tooltip_options form, key, options
if options[:as] == :boolean if options[:as] == :boolean
checked_value = options.delete(:checked_value) || 'true'
unchecked_value = options.delete(:unchecked_value) || 'false'
options[:checked] = 'checked' if options.delete(:value) options[:checked] = 'checked' if options.delete(:value)
form.hidden_field(key, value: false, as: :hidden) + form.check_box(key, options, true, false) form.hidden_field(key, value: unchecked_value, as: :hidden) + form.check_box(key, options, checked_value, false)
else else
form.input_field key, options form.input_field key, options
end end