module FormHelpers # params is an array of hashes for ordering. has structure is described # in the usage msg def self.auto_form(params=[], objs=[]) msg =< 0 && objs.nitems > 0 checkbox_state=[true, false] params.each { |i| objs.each {|o| key = i.keys.first value = i.values.first next unless key.to_s =~ /^command_/ object_class='' current='' element = key.to_s.split('command_').last if o.respond_to?(element) eval "object_class = o.#{element}.class.to_s" if object_class =~ /checkbox/i raise ArgumentError unless checkbox_state.include?(value) eval "current = o.#{element}.checked?" o.send(element).set(value) if object_class =~ /radio/i if value o.send(element).check else o.send(element).uncheck end end elsif object_class =~ /selectlist/i o.send(element).select(value) elsif object_class =~ /textfield/i # skip if key supplied but empty string or nil o.send(element).set(value) #unless value != '' elsif object_class =~ /button|link|image/i eval "o.#{element}.#{value}" end end } } end end