fix simple_form deprecations

This commit is contained in:
wvengen 2014-12-10 22:03:17 +01:00
parent 7ac3f54709
commit 12bf2198e5
4 changed files with 19 additions and 16 deletions

View file

@ -2,24 +2,25 @@
class DeltaInput < SimpleForm::Inputs::StringInput
# for now, need to pass id or it won't work
def input
@input_html_options[:type] = 'text'
@input_html_options[:data] ||= {}
@input_html_options[:data][:delta] ||= 1
@input_html_options[:autocomplete] ||= 'off'
def input(wrapper_options)
options = merge_wrapper_options(input_html_options, wrapper_options)
options[:type] = 'text'
options[:data] ||= {}
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
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
#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
def delta_button(title, direction)
data = { (direction>0 ? 'increment' : 'decrement') => @input_html_options[:id] }
delta = direction * @input_html_options[:data][:delta]
def delta_button(title, direction, options)
data = { (direction>0 ? 'increment' : 'decrement') => options[:id] }
delta = direction * options[:data][:delta]
template.button_tag(title, type: :button, name: 'delta', value: delta, data: data, tabindex: -1, class: 'btn')
end
end