class Pakyow::Presenter::Views::Form
Constants
- CHECKBOX_TYPE
- CHECKED_TYPES
- FIELD_TAGS
- INPUT_TAG
- RADIO_TYPE
- SELECT_TAG
- TEXTAREA_TAG
Private Instance Methods
bind_value_to_node(value, node)
click to toggle source
Calls superclass method
Pakyow::Presenter::View#bind_value_to_node
# File lib/pakyow/presenter/views/form.rb, line 32 def bind_value_to_node(value, node) super if node.tagname == SELECT_TAG select_option_with_value(value, View.from_object(node)) end if CHECKED_TYPES.include?(node.attributes[:type]) check_or_uncheck_value(value, View.from_object(node)) end end
check_or_uncheck_value(value, view)
click to toggle source
# File lib/pakyow/presenter/views/form.rb, line 44 def check_or_uncheck_value(value, view) if view.attributes[:type] == "checkbox" # There could be multiple values checked, so check for inclusion. # view.attributes[:checked] = Array.ensure(value).map(&:to_s).include?(view.attributes[:value]) else view.attributes[:checked] = view.attributes[:value] == value.to_s end end
select_option_with_value(value, view)
click to toggle source
# File lib/pakyow/presenter/views/form.rb, line 54 def select_option_with_value(value, view) view.object.each_significant_node(:option) do |option| View.from_object(option).attributes[:selected] = option.attributes[:value] == value end end