Sha256: 94fe9d6339b4e73de0528202f20aac324f66e356a20f295b31fc3634466c543f

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

module JqueryUiForm 
  module Inputs
    module RadioInput
      
      def radio_input(method, options = {})
        # radio_button(method, tag_value, 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
        value = nil
        if options[:value]
          value = options.delete(:value)
        elsif @object
          value = @object.send(method)          
        end
        output = fieldset(legend.html_safe, fieldset_options) do
          template.concat(inline_hint(options.delete(:hint)))
          template.concat(inline_error(method))
          collection.each do |row|
            name, id = (row.is_a?(Array) ? row : [row, row])
            checked = value.to_s == id.to_s
            if buttonset
              template.concat(radio_button(method, id, options.merge(:checked => checked)))
              template.concat(label(name_to_id("#{method}_#{id}"), name, label_options))
            else
              template.concat(column do
                template.concat(label(name_to_id("#{method}_#{id}"), name, label_options))
                template.concat(radio_button(method, id, options.merge(:checked => checked)))
              end)
            end
          end
        end
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jquery-ui-form-0.2.8 lib/jquery_ui_form/inputs/radio_input.rb
jquery-ui-form-0.2.7 lib/jquery_ui_form/inputs/radio_input.rb