motion-prime/sections/form.rb in motion-prime-1.0.5 vs motion-prime/sections/form.rb in motion-prime-1.0.6

- old
+ new

@@ -118,12 +118,12 @@ self.collection_view.height += KEYBOARD_HEIGHT_PORTRAIT self.keyboard_visible = false end def keyboard_will_show - return if collection_view.contentSize.height + collection_view.top <= UIScreen.mainScreen.bounds.size.height - KEYBOARD_HEIGHT_PORTRAIT current_inset = collection_view.contentInset + return if collection_view.contentSize.height + collection_view.top + current_inset.top <= UIScreen.mainScreen.bounds.size.height - KEYBOARD_HEIGHT_PORTRAIT current_inset.bottom = KEYBOARD_HEIGHT_PORTRAIT + (self.collection_element.computed_options[:bottom_content_inset] || 0) collection_view.contentInset = current_inset end def keyboard_will_hide @@ -161,11 +161,10 @@ condition.to_proc.call(self) end end def reload_data - @groups_count = nil init_form_fields # must be before resetting to reflect changes on @data reset_collection_data reload_collection_data end @@ -248,34 +247,35 @@ self.fields = {} self.field_indexes = {} self.grouped_data = [] section_indexes = [] - (self.class.fields_options || {}).each do |key, field| - next unless render_field?(key, field) - section_id = field[:group].to_i - @groups_count = [@groups_count || 1, section_id + 1].max - grouped_data[section_id] ||= [] - section_indexes[section_id] ||= 0 + grouped_fields = (self.class.fields_options || {}).inject([]) do |result, (key, field)| + next result unless render_field?(key, field) + group_id = field[:group].to_i + result[group_id] ||= {} + result[group_id][key] = field + result + end - section = load_field(field) - if section.options[:after_render].present? - puts "DEPRECATION: form field's option :after_render is deprecated, please use Prime::Section#after_field_render instead" - end - self.fields[key] = section - self.field_indexes[key] = NSIndexPath.indexPathForRow(section_indexes[section_id], inSection: section_id) - grouped_data[section_id][section_indexes[section_id]] = section + header_options = Array.wrap(self.class.group_header_options).map(&:clone) + header_options.each { |opts| normalize_options(opts) if opts } + self.group_header_options = header_options.delete_if.each_with_index { |opts, id| grouped_fields[id].blank? } - section_indexes[section_id] += 1 + grouped_fields.compact.each_with_index do |fields, group_id| + fields.each_with_index do |(key, field), row_id| + section = load_field(field) + if section.options[:after_render].present? + puts "DEPRECATION: form field's option :after_render is deprecated, please use Prime::Section#after_field_render instead" + end + self.fields[key] = section + self.field_indexes[key] = NSIndexPath.indexPathForRow(row_id, inSection: group_id) + grouped_data[group_id] ||= [] + grouped_data[group_id][row_id] = section + end end - init_form_headers - reset_data_stamps - end - def init_form_headers - options = Array.wrap(self.class.group_header_options).map(&:clone) - options.compact.each { |opts| normalize_options(opts) } - self.group_header_options = options.delete_if.each_with_index { |opts, id| grouped_data[id].nil? } + reset_data_stamps end end end \ No newline at end of file