5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/jquery_ui_form/inputs/radio_input.rb', line 5
def radio_input(method, options = {})
legend, options = label_text(method, options)
collection = options.delete(:collection)
label_options = options.delete(:html_label) || {}
label_options[:required] = options.delete(:required)
buttonset = options.delete(:buttonset) || false
fieldset_options = {}
fieldset_options[:class] = "to-buttonset" if buttonset
output = fieldset(legend.html_safe, fieldset_options) do
template.concat(inline_hint(options.delete(:hint)))
template.concat(inline_error(method))
collection.each do |row|
value, id = (row.is_a?(Array) ? row : [row, row])
if @object
checked = @object.send(method) == id
else
checked = options[:value] == id
end
if buttonset
template.concat(radio_button(method, id, options.merge(:checked => checked)))
template.concat(label(name_to_id("#{method}_#{id}"), value, label_options))
else
template.concat(column do
template.concat(label(name_to_id("#{method}_#{id}"), value, label_options))
template.concat(radio_button(method, id, options.merge(:checked => checked)))
end)
end
end
end
end
|