add select list options

master
Kanezoh 2021-07-01 19:08:28 +09:00
parent 18e948616a
commit a6111294ad
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
class MechanizeCr::FormContent::Option
getter select_list : FormContent::MultiSelectList
getter node : Myhtml::Node
getter text : String
getter value : String
getter selected : Bool
def initialize(node, select_list)
@node = node
@text = node.inner_text
@value = (node["value"] || node.inner_text)
@selected = node.has_key?("selected")
@select_list = select_list # The select list this option belongs to
end
# Select this option
def select
unselect_peers
@selected = true
end
# Unselect this option
def unselect
@selected = false
end
# Toggle the selection value of this option
def click
unselect_peers
@selected = !@selected
end
def selected?
@selected
end
private def unselect_peers
return unless SelectList === @select_list
@select_list.select_none
end
end