Class: TextInputRow
  
  
  
  
    
      Constant Summary
      collapse
    
    
      
        - EMAIL_REGEX =
          
        
- /^[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
- URL_REGEX =
          
        
- /https?:\/\/[\S]+/ 
Instance Attribute Summary collapse
  
  
  
  Attributes inherited from BaseRow
  #key, #label, #options
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from BaseRow
  #cell_identifier, #dealloc, #has_value?, #notification_center, #observe, #post
  Constructor Details
  
    
  
  
    #initialize(key, options)  ⇒ TextInputRow 
  
  
  
  
    
Returns a new instance of TextInputRow.
   
 
  
  
    | 
10
11
12
13
14
15
16 | # File 'lib/project/rows/text_input_row.rb', line 10
def initialize(key, options)
  super
  setup_validation
  listen
end | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #value  ⇒ Object 
  
  
  
  
    
Returns the value of attribute value.
   
 
  
  
    | 
8
9
10 | # File 'lib/project/rows/text_input_row.rb', line 8
def value
  @value
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #capitalize?  ⇒ Boolean 
  
  
  
  
    | 
68
69
70 | # File 'lib/project/rows/text_input_row.rb', line 68
def capitalize?
  options[:capitalize] || !(options[:email] || options[:secure])
end | 
 
    
      
  
  
    #cell_type  ⇒ Object 
  
  
  
  
    | 
72
73
74 | # File 'lib/project/rows/text_input_row.rb', line 72
def cell_type
  TextInputCell
end | 
 
    
      
  
  
    #did_end_editing(notification)  ⇒ Object 
  
  
  
  
    | 
52
53
54 | # File 'lib/project/rows/text_input_row.rb', line 52
def did_end_editing(notification)
  self.value = notification.userInfo[:value] if notification.userInfo[:key] == key
end | 
 
    
      
  
  
    #listen  ⇒ Object 
  
  
  
  
    | 
48
49
50 | # File 'lib/project/rows/text_input_row.rb', line 48
def listen
  observe('FormCellDidEndEditing', 'did_end_editing:')
end | 
 
    
      
  
  
    #setup_validation  ⇒ Object 
  
  
  
  
    | 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 | # File 'lib/project/rows/text_input_row.rb', line 18
def setup_validation
  if options[:required]
    validation_rules << lambda { |value| value && value != '' }
  end
  if options[:email]
    validation_rules << lambda { |value| value && value[EMAIL_REGEX] }
  end
  if options[:url]
    validation_rules << lambda { |value| value && value[URL_REGEX] }
  end
  if options[:format] && options[:format].is_a?(Regexp)
    validation_rules << lambda { |value| value && value[options[:format]] }
  end
  if options[:validate_with] && options[:validate_with].is_a?(Proc)
    validation_rules << options[:validate_with]
  end
end | 
 
    
      
  
  
    #textFieldDidEndEditing(text_field)  ⇒ Object 
  
  
  
  
    | 
56
57
58 | # File 'lib/project/rows/text_input_row.rb', line 56
def textFieldDidEndEditing(text_field)
  self.value = text_field.text
end | 
 
    
      
  
  
    #update_cell(cell)  ⇒ Object 
  
  
  
  
    | 
60
61
62
63
64
65
66 | # File 'lib/project/rows/text_input_row.rb', line 60
def update_cell(cell)
  super
  cell.secure     = options[:secure]
  cell.value      = options[:value]
  cell.capitalize = capitalize?
end | 
 
    
      
  
  
    #valid?  ⇒ Boolean 
  
  
  
  
    | 
40
41
42 | # File 'lib/project/rows/text_input_row.rb', line 40
def valid?
  validation_rules.all? { |rule| rule.call(value) }
end | 
 
    
      
  
  
    #validation_rules  ⇒ Object 
  
  
  
  
    | 
44
45
46 | # File 'lib/project/rows/text_input_row.rb', line 44
def validation_rules
  @validation_rules ||= []
end |