Class: MotionPrime::FormDelegate

Inherits:
TableDelegate show all
Defined in:
motion-prime/sections/form/form_delegate.rb

Instance Attribute Summary

Attributes inherited from TableDelegate

#table_section

Instance Method Summary collapse

Methods inherited from TableDelegate

#dealloc, #init_pull_to_refresh, #initialize, #numberOfSectionsInTableView, #scrollViewDidEndDecelerating, #scrollViewDidEndDragging, #scrollViewDidScroll, #scrollViewWillBeginDragging, #tableView

Methods included from DelegateMixin

#clear_delegated, #delegated_by

Constructor Details

This class inherits a constructor from MotionPrime::TableDelegate

Instance Method Details

#textField(text_field, shouldChangeCharactersInRange: range, replacementString: string) ⇒ Object



17
18
19
20
21
22
23
# File 'motion-prime/sections/form/form_delegate.rb', line 17

def textField(text_field, shouldChangeCharactersInRange:range, replacementString:string)
  limit = (table_section.class.text_field_limits || {}).find do |field_name, limit|
    table_section.view("#{field_name}:input") == text_field
  end.try(:last)
  return true unless limit
  table_section.allow_string_replacement?(text_field, limit, range, string)
end

#textFieldDidBeginEditing(text_field) ⇒ Object



10
11
12
# File 'motion-prime/sections/form/form_delegate.rb', line 10

def textFieldDidBeginEditing(text_field)
  table_section.on_input_edit_begin(text_field)
end

#textFieldDidEndEditing(text_field) ⇒ Object



13
14
15
# File 'motion-prime/sections/form/form_delegate.rb', line 13

def textFieldDidEndEditing(text_field)
  table_section.on_input_edit_end(text_field)
end

#textFieldShouldBeginEditing(text_field) ⇒ Object



7
8
9
# File 'motion-prime/sections/form/form_delegate.rb', line 7

def textFieldShouldBeginEditing(text_field)
  text_field.respond_to?(:readonly) ? !text_field.readonly : true
end

#textFieldShouldReturn(text_field) ⇒ Object



4
5
6
# File 'motion-prime/sections/form/form_delegate.rb', line 4

def textFieldShouldReturn(text_field)
  table_section.on_input_return(text_field)
end

#textView(text_view, shouldChangeTextInRange: range, replacementText: string) ⇒ Object



44
45
46
# File 'motion-prime/sections/form/form_delegate.rb', line 44

def textView(text_view, shouldChangeTextInRange:range, replacementText:string)
  textField(text_view, shouldChangeCharactersInRange:range, replacementString:string)
end

#textViewDidBeginEditing(text_view) ⇒ Object



25
26
27
# File 'motion-prime/sections/form/form_delegate.rb', line 25

def textViewDidBeginEditing(text_view)
  table_section.on_input_edit_begin(text_view)
end

#textViewDidChange(text_view) ⇒ Object

bug in iOS 7 - cursor is out of textView bounds



31
32
33
34
35
36
37
38
39
40
41
42
# File 'motion-prime/sections/form/form_delegate.rb', line 31

def textViewDidChange(text_view) # bug in iOS 7 - cursor is out of textView bounds
  line = text_view.caretRectForPosition(text_view.selectedTextRange.start)
  overflow = line.origin.y + line.size.height -
    (text_view.contentOffset.y + text_view.bounds.size.height - text_view.contentInset.bottom - text_view.contentInset.top)
  if overflow > 0
    offset = text_view.contentOffset
    offset.y += overflow + text_view.textContainerInset.bottom
    UIView.animate(duration: 0.2) do
      text_view.setContentOffset(offset)
    end
  end
end

#textViewDidEndEditing(text_view) ⇒ Object



28
29
30
# File 'motion-prime/sections/form/form_delegate.rb', line 28

def textViewDidEndEditing(text_view)
  table_section.on_input_edit_end(text_view)
end