Sha256: e059dbc29b4d99328c6c63ccad428ccca0656954a0c256d177dd4c94422dff83

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module MotionPrime
  class BaseFieldSection < BaseSection
    attr_accessor :form

    def initialize(options = {})
      super
      @form = options.delete(:form)
      @container_options = options.delete(:container)
    end

    def form_name
      form.name
    end

    def container_options
      @container_options || super
    end

    def cell
      first_element = elements.values.first
      first_element.view.superview
    end

    def focus(begin_editing = true)
      # scroll to cell
      path = form.table_view.indexPathForCell cell
      form.table_view.scrollToRowAtIndexPath path,
        atScrollPosition: UITableViewScrollPositionTop, animated: true
      # focus on text field
      return unless begin_editing
      elements.values.each do |element|
        if element.view.is_a?(UITextField)
          element.view.becomeFirstResponder && return
        end
      end
      self
    rescue
      puts "can't focus on element #{self.class.name}"
    end

    def blur
      elements.values.each do |element|
        if element.view.is_a?(UITextField)
          element.view.resignFirstResponder && return
        end
      end
      self
    rescue
      puts "can't blur on element #{self.class.name}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-prime-0.1.4 motion-prime/sections/form/base_field_section.rb