Sha256: b4bb29d505e4bf2653dde2d3181023c624fd786fe8ec950e8d81c9b6110d80b0

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 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

    def bind_text_input
      view(:input).on :change do |view|
        focus
        form.on_input_change(view(:input))
      end
      view(:input).delegate = self.form
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
motion-prime-0.1.7 motion-prime/sections/form/base_field_section.rb
motion-prime-0.1.6 motion-prime/sections/form/base_field_section.rb
motion-prime-0.1.5 motion-prime/sections/form/base_field_section.rb