Class: SimpleForm::Inputs::AutocompleteCollectionInput
- Inherits:
-
CollectionInput
- Object
- CollectionInput
- SimpleForm::Inputs::AutocompleteCollectionInput
show all
- Includes:
- Autocomplete
- Defined in:
- lib/rails-jquery-autocomplete/simple_form_plugin.rb
Instance Method Summary
collapse
#rewrite_autocomplete_option
Instance Method Details
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/rails-jquery-autocomplete/simple_form_plugin.rb', line 50
def input(opts)
hidden_id = "#{object_name}_#{attribute_name}_hidden".gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
id_element = options[:id_element]
if id_element
id_element << ", #" << hidden_id
else
id_element = "#" + hidden_id
end
options[:id_element] = id_element
if opts.nil?
autocomplete_options = rewrite_autocomplete_option
else
merge_wrapper_options(rewrite_autocomplete_option, args)
end
label_method, value_method = detect_collection_methods
association = object.send(reflection.name)
if association && association.respond_to?(label_method)
autocomplete_options[:value] = association.send(label_method)
end
out = @builder.autocomplete_field(
attribute_name,
options[:url],
autocomplete_options
)
hidden_options = if association && association.respond_to?(value_method)
new_options = {}
new_options[:value] = association.send(value_method)
input_html_options.merge new_options
else
input_html_options
end
hidden_options[:id] = hidden_id
out << @builder.hidden_field(
attribute_name,
hidden_options
)
out.html_safe
end
|