motion-prime/sections/form.rb in motion-prime-0.1.4 vs motion-prime/sections/form.rb in motion-prime-0.1.5

- old
+ new

@@ -52,11 +52,15 @@ # # @param String name with format "fieldname:elementname" # @return MotionPrime::BaseElement element def element(name) field_name, element_name = name.split(':') - field(field_name).element(element_name.to_sym) + if element_name.present? + field(field_name).element(element_name.to_sym) + else + super(field_name) + end end # Returns field by name # # Examples: @@ -82,12 +86,10 @@ end # focus on field field(field_name).focus end - def on_edit(field); end - class << self def field(name, options = {}) options[:name] = name options[:type] ||= :string self.fields_options ||= {} @@ -106,24 +108,45 @@ return unless keyboard_visible self.table_view.height += KEYBOARD_HEIGHT_PORTRAIT self.keyboard_visible = false end - def on_keyboard_show - end - def on_keyboard_hide - end + def on_keyboard_show; end + def on_keyboard_hide; end + def keyboard_will_show; end + def keyboard_will_hide; end + def bind_keyboard_events NSNotificationCenter.defaultCenter.addObserver self, selector: :on_keyboard_show, name: UIKeyboardDidShowNotification, object: nil NSNotificationCenter.defaultCenter.addObserver self, selector: :on_keyboard_hide, name: UIKeyboardDidHideNotification, object: nil + NSNotificationCenter.defaultCenter.addObserver self, + selector: :keyboard_will_show, + name: UIKeyboardWillShowNotification, + object: nil + NSNotificationCenter.defaultCenter.addObserver self, + selector: :keyboard_will_hide, + name: UIKeyboardWillHideNotification, + object: nil + end + # ALIASES + def on_input_change(text_field); end + def on_input_edit(text_field); end + def on_input_return(text_field) + text_field.resignFirstResponder + end; + def textFieldShouldReturn(text_field) + on_input_return(text_field) + end + def textFieldDidBeginEditing(text_field) + on_input_edit(text_field) end private def init_form_fields \ No newline at end of file