fix simple_form deprecations
This commit is contained in:
parent
7ac3f54709
commit
12bf2198e5
4 changed files with 19 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
||||||
class DatePickerInput < SimpleForm::Inputs::StringInput
|
class DatePickerInput < SimpleForm::Inputs::StringInput
|
||||||
def input
|
def input(wrapper_options)
|
||||||
@builder.text_field(attribute_name, input_html_options.merge({class: 'datepicker'}))
|
options = merge_wrapper_options(input_html_options, wrapper_options)
|
||||||
|
@builder.text_field attribute_name, options.merge(class: 'datepicker')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
# @see http://stackoverflow.com/a/20317763/2866660
|
# @see http://stackoverflow.com/a/20317763/2866660
|
||||||
# @see https://github.com/einzige/date_time_attribute
|
# @see https://github.com/einzige/date_time_attribute
|
||||||
class DatePickerTimeInput < SimpleForm::Inputs::StringInput
|
class DatePickerTimeInput < SimpleForm::Inputs::StringInput
|
||||||
def input
|
def input(wrapper_options)
|
||||||
|
options = merge_wrapper_options(input_html_options, wrapper_options)
|
||||||
# Date format must match datepicker's, see app/assets/application.js .
|
# Date format must match datepicker's, see app/assets/application.js .
|
||||||
# And for html5 inputs, match RFC3339, see http://dev.w3.org/html5/markup/datatypes.html#form.data.date .
|
# And for html5 inputs, match RFC3339, see http://dev.w3.org/html5/markup/datatypes.html#form.data.date .
|
||||||
# In the future, use html5 date&time inputs. This needs modernizr or equiv. to avoid
|
# In the future, use html5 date&time inputs. This needs modernizr or equiv. to avoid
|
||||||
|
@ -13,8 +14,8 @@ class DatePickerTimeInput < SimpleForm::Inputs::StringInput
|
||||||
value = @builder.object.send attribute_name
|
value = @builder.object.send attribute_name
|
||||||
date_options = {as: :string, class: 'input-small datepicker'}
|
date_options = {as: :string, class: 'input-small datepicker'}
|
||||||
time_options = {as: :string, class: 'input-mini'}
|
time_options = {as: :string, class: 'input-mini'}
|
||||||
@builder.input_field("#{attribute_name}_date_value", input_html_options.merge(date_options)) + ' ' +
|
@builder.input_field("#{attribute_name}_date_value", options.merge(date_options)) + ' ' +
|
||||||
@builder.input_field("#{attribute_name}_time_value", input_html_options.merge(time_options))
|
@builder.input_field("#{attribute_name}_time_value", options.merge(time_options))
|
||||||
# time_select requires a date_select
|
# time_select requires a date_select
|
||||||
#@builder.time_select("#{attribute_name}_time", {ignore_date: true}, input_html_options.merge(time_options))
|
#@builder.time_select("#{attribute_name}_time", {ignore_date: true}, input_html_options.merge(time_options))
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,24 +2,25 @@
|
||||||
|
|
||||||
class DeltaInput < SimpleForm::Inputs::StringInput
|
class DeltaInput < SimpleForm::Inputs::StringInput
|
||||||
# for now, need to pass id or it won't work
|
# for now, need to pass id or it won't work
|
||||||
def input
|
def input(wrapper_options)
|
||||||
@input_html_options[:type] = 'text'
|
options = merge_wrapper_options(input_html_options, wrapper_options)
|
||||||
@input_html_options[:data] ||= {}
|
options[:type] = 'text'
|
||||||
@input_html_options[:data][:delta] ||= 1
|
options[:data] ||= {}
|
||||||
@input_html_options[:autocomplete] ||= 'off'
|
options[:data][:delta] ||= 1
|
||||||
|
options[:autocomplete] ||= 'off'
|
||||||
# TODO get generated id, don't know how yet - `add_default_name_and_id_for_value` might be an option
|
# TODO get generated id, don't know how yet - `add_default_name_and_id_for_value` might be an option
|
||||||
|
|
||||||
template.content_tag :div, class: 'delta-input input-prepend input-append' do
|
template.content_tag :div, class: 'delta-input input-prepend input-append' do
|
||||||
delta_button('−', -1) + super + delta_button('+', 1)
|
delta_button('−', -1, options) + @builder.text_field(attribute_name, options) + delta_button('+', 1, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#template.button_tag('−', type: :submit, data: {decrement: @input_html_options[:id]}, tabindex: -1, class: 'btn') +
|
#template.button_tag('−', type: :submit, data: {decrement: options[:id]}, tabindex: -1, class: 'btn') +
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def delta_button(title, direction)
|
def delta_button(title, direction, options)
|
||||||
data = { (direction>0 ? 'increment' : 'decrement') => @input_html_options[:id] }
|
data = { (direction>0 ? 'increment' : 'decrement') => options[:id] }
|
||||||
delta = direction * @input_html_options[:data][:delta]
|
delta = direction * options[:data][:delta]
|
||||||
template.button_tag(title, type: :button, name: 'delta', value: delta, data: data, tabindex: -1, class: 'btn')
|
template.button_tag(title, type: :button, name: 'delta', value: delta, data: data, tabindex: -1, class: 'btn')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,7 +98,7 @@ SimpleForm.setup do |config|
|
||||||
config.label_class = 'control-label'
|
config.label_class = 'control-label'
|
||||||
|
|
||||||
# You can define the class to use on all forms. Default is simple_form.
|
# You can define the class to use on all forms. Default is simple_form.
|
||||||
config.form_class = 'form-horizontal'
|
config.default_form_class = 'form-horizontal'
|
||||||
|
|
||||||
# You can define which elements should obtain additional classes
|
# You can define which elements should obtain additional classes
|
||||||
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
||||||
|
|
Loading…
Reference in a new issue