lib/formotion/form/form.rb in formotion-1.1.4 vs lib/formotion/form/form.rb in formotion-1.1.5

- old
+ new

@@ -192,9 +192,37 @@ kv[subform_row.key] = subform_row.subform.to_form.render end kv end + def values=(data) + self.sections.each {|section| + if section.select_one? + # see if one of the select one value is used + unless (section.rows.map{ |r| r.key } & data.keys).empty? + section.rows.each { |row| + row.value = data.has_key?(row.key) ? true : nil + } + end + else + section.rows.each {|row| + next if row.button? + if row.template_parent + # If this row is part of a template + # use the parent's key + row.value = data[row.template_parent_key] if data.has_key?(row.template_parent_key) + elsif row.subform + row.subform.to_form.values = data + else + row.value = data[row.key] if data.has_key?(row.key) + end + } + end + } + end + + alias_method :fill_out, :values= + ######################### # Persisting Forms # loads the given settings into the the form, and # places observers to save on changes