Permalink
Browse files

`:editable` property

  • Loading branch information...
1 parent df2b50f commit 3d9459da6ff2f636c0227f91d6d6565ec3fa5f4b @clayallsopp committed Dec 17, 2012
View
@@ -6,6 +6,8 @@
- Added `:text_alignment` row property which controls how a row's input field's text is aligned (i.e. `:right` (default), `:left`, or `:center`).
+- Added `:editable` row property which controls if a user can interact with the row's control (a text input, slider, etc)
+
### Bug Fixes
- Fixed size issue with iPhone apps running @2x on an iPad (see `row_type/base.rb#field_buffer`)
View
@@ -22,6 +22,10 @@ class Row < Formotion::Base
:format,
# alternative title for row (only used in EditRow for now)
:alt_title,
+ # determines if the user can edit the row
+ # OPTIONS: true, false
+ # DEFAULT: true
+ :editable,
# The following apply only to text-input fields
@@ -230,6 +234,29 @@ def text_alignment=(alignment)
@text_alignment = const_int_get("UITextAlignment", alignment)
end
+ def editable=(editable)
+ case editable
+ when TrueClass
+ when FalseClass
+ when NSNull
+ editable = false
+ when NilClass
+ editable = false
+ when NSString
+ editable = (editable == "true")
+ else
+ raise Formotion::InvalidClassError, "Invalid class for `Row#editable`: #{editable.inspect}; should be TrueClass, FalseCLass, or NSString"
+ end
+ @editable = editable
+ end
+
+ def editable?
+ if !self.editable.nil?
+ return self.editable
+ end
+ true
+ end
+
#########################
# setters for callbacks
@@ -20,6 +20,9 @@ def build_cell(cell)
end
def on_select(tableView, tableViewDelegate)
+ if !row.editable?
+ return
+ end
if row.section.select_one and !row.value
row.section.rows.each do |other_row|
other_row.value = (other_row == row)
@@ -45,6 +45,9 @@ def layoutSubviews
end
def on_select(tableView, tableViewDelegate)
+ if !row.editable?
+ return
+ end
@action_sheet = UIActionSheet.alloc.init
@action_sheet.delegate = self
@@ -10,6 +10,7 @@ def build_cell(cell)
segmentedControl = UISegmentedControl.alloc.initWithItems(item_names || [])
segmentedControl.selectedSegmentIndex = name_index_of_value(row.value) if row.value
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar
+ segmentedControl.userInteractionEnabled = row.editable?
cell.accessoryView = cell.editingAccessoryView = segmentedControl
segmentedControl.when(UIControlEventValueChanged) do
@@ -15,6 +15,7 @@ def build_cell(cell)
slideView.tag = SLIDER_VIEW_TAG
slideView.setValue(row.value, animated:true) if row.value
slideView.accessibilityLabel = (row.title || "") + " Slider"
+ slideView.userInteractionEnabled = row.editable?
slideView.when(UIControlEventValueChanged) do
break_with_semaphore do
@@ -39,6 +39,7 @@ def build_cell(cell)
field.autocapitalizationType = row.auto_capitalization if row.auto_capitalization
field.autocorrectionType = row.auto_correction if row.auto_correction
field.clearButtonMode = row.clear_button || UITextFieldViewModeWhileEditing
+ field.enabled = row.editable?
add_callbacks(field)
@@ -127,6 +128,9 @@ def on_change(text_field)
end
def on_select(tableView, tableViewDelegate)
+ if !row.editable?
+ return
+ end
row.text_field.becomeFirstResponder
end
@@ -14,6 +14,7 @@ def build_cell(cell)
row.value = switchView.isOn
end
end
+ switchView.userInteractionEnabled = row.editable?
observe(self.row, "value") do |old_value, new_value|
break_with_semaphore do
switchView.setOn(row.value || false, animated: false)
@@ -20,6 +20,7 @@ def build_cell(cell)
field.autocapitalizationType = row.auto_capitalization if row.auto_capitalization
field.autocorrectionType = row.auto_correction if row.auto_correction
field.placeholder = row.placeholder
+ field.enabled = row.editable?
field.on_begin do |text_field|
row.on_begin_callback && row.on_begin_callback.call
@@ -72,6 +73,9 @@ def layoutSubviews
end
def on_select(tableView, tableViewDelegate)
+ if !row.editable?
+ return
+ end
field.becomeFirstResponder
end

0 comments on commit 3d9459d

Please sign in to comment.