16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/shimmer/form/builder.rb', line 16
def input(method, as: guess_type(method), wrapper_options: {}, description: nil, label_method: nil, id_method: :id, name_method: nil, label: nil, **options)
as ||= guess_type(method)
options[:class] ||= "input__input"
collection = options.delete :collection
collection_based = !collection.nil? || as == :select
collection ||= guess_collection(method) if collection_based
name_method ||= guess_name_method(method) if collection_based
id_method ||= :id if collection_based
classes = []
options[:required] ||= true if options[:required].nil? && required_attributes.include?(method)
options[:data] ||= {}
options[:data][:controller] = options.delete(:controller) if options[:controller]
= []
input_class = self.class.input_registry[as]
raise "Unknown type #{as}" unless input_class
input = input_class.new(builder: self, method: method, options: options, id_method: id_method, collection: collection, name_method: name_method)
input.prepare
wrapper_options.reverse_merge! input.wrapper_options
label_method ||= wrapper_options.delete(:label_method)
wrap method: method, content: input.render, classes: classes + ["input--#{as}"], label: label, extra: , description: description, options: wrapper_options, label_method: label_method
end
|