add select list options
This commit is contained in:
parent
18e948616a
commit
a6111294ad
41
src/mechanize/form/option.cr
Normal file
41
src/mechanize/form/option.cr
Normal 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
|
Loading…
Reference in New Issue
Block a user