lib/scaffolding_extensions/helper.rb
# Forms an input field for the given field_type.
#
# The following field types are recognized:
# * :text => textarea
# * :boolean => select box with blank (NULL), True, and False
# * :association => select box or autocompleteing text box for the association
# * :submit, :password, :hidden, :file => input tag with matching type
# * everything else => input tag with type text
#
# Options are converted to html attributes, with the following special options:
# * :value => the value of the tag, which usually will be just an html attribute,
#   but can be the html inside the textarea, or the choice of selection
#   for one of the selection options
# * :id => if :name is blank, it is also used for :name
Forms an input field for the given field_type.


Forms an input field for the given field_type .
def scaffold_field_tag(field_type, options, object=nil, field=nil, record_name=nil, field_id=nil)
        options[:name] ||= options[:id] if options[:id]
        value = options[:value] || object.scaffold_value(field)
        case field_type
          when :text
            "<textarea #{scaffold_options_to_html(options)}>#{h value.to_s}</textarea>"
          when :boolean
            s = {value=>"selected='selected'"}
            "<select #{scaffold_options_to_html(options)}><option></option><option value='f' #{s[false]}>False</option><option value='t' #{s[true]}>True</option></select>"
          when :association
            klass = object.class
            if klass.scaffold_association_use_auto_complete(field)
              assocated_object = klass.scaffold_associated_objects(field, object, :session=>scaffold_session)
              options[:value] = assocated_object ? assocated_object.scaffold_name_with_id : ''
              scaffold_text_field_tag_with_auto_complete(options[:id], record_name, field, options)
            else
              s = {object.scaffold_value(field_id).to_i=>"selected='selected'"}
              associated_objects = klass.scaffold_association_find_objects(field, :session=>scaffold_session, :object=>object)
              "<select #{scaffold_options_to_html(options)}><option></option>#{associated_objects.collect{|ao| "<option value='#{i = ao.scaffold_id}' #{s[i]}>#{h ao.scaffold_name}</option>"}.join}</select>"
            end
          when :enum
            select_options = options.delete(:select_options) || []
            s = {value.to_s => "selected='selected'"}
            "<select #{scaffold_options_to_html(options)}><option></option>#{select_options.collect{|o| "<option value='#{o[1]}' #{s[o[1]]}>#{o[0].to_s}</option>"}.join}</select>"
          else
            options[:type] = :text
            case field_type
              when :submit, :password, :hidden, :file
                options[:size] ||= 30 if field_type == :password 
                options[:type] = field_type
              when :date, :integer, :float
                options[:size] ||= 10
              else
                options[:size] ||= 30
            end
            options[:value] ||= value
            "<input #{scaffold_options_to_html(options)} />"
        end
      end
def scaffold_field_tag ( field_type , options , object = nil , field = nil , record_name = nil , field_id = nil ) options [ :name ] ||= options [ :id ] if options [ :id ] value = options [ :value ] || object . scaffold_value ( field ) case field_type when :text "<textarea #{scaffold_options_to_html(options)}>#{h value.to_s}</textarea>" when :boolean s = { value => "selected='selected'" } "<select #{scaffold_options_to_html(options)}><option></option><option value='f' #{s[false]}>False</option><option value='t' #{s[true]}>True</option></select>" when :association klass = object . class if klass . scaffold_association_use_auto_complete ( field ) assocated_object = klass . scaffold_associated_objects ( field , object , :session => scaffold_session ) options [ :value ] = assocated_object ? assocated_object . scaffold_name_with_id : '' scaffold_text_field_tag_with_auto_complete ( options [ :id ] , record_name , field , options ) else s = { object . scaffold_value ( field_id ) . to_i => "selected='selected'" } associated_objects = klass . scaffold_association_find_objects ( field , :session => scaffold_session , :object => object ) "<select #{scaffold_options_to_html(options)}><option></option>#{associated_objects.collect{|ao| "<option value='#{i = ao.scaffold_id}' #{s[i]}>#{h ao.scaffold_name}</option>"}.join}</select>" end when :enum select_options = options . delete ( :select_options ) || [ ] s = { value . to_s => "selected='selected'" } "<select #{scaffold_options_to_html(options)}><option></option>#{select_options.collect{|o| "<option value='#{o[1]}' #{s[o[1]]}>#{o[0].to_s}</option>"}.join}</select>" else options [ :type ] = :text case field_type when :submit , :password , :hidden , :file options [ :size ] ||= 30 if field_type == :password options [ :type ] = field_type when :date , :integer , :float options [ :size ] ||= 10 else options [ :size ] ||= 30 end options [ :value ] ||= value "<input #{scaffold_options_to_html(options)} />" end end
Forms an input field for the given field_type.
Forms an input field for the given field_type .
field_type
options
object
field
record_name
field_id