add checkbox comment
This commit is contained in:
parent
fca04b29b9
commit
794a2085de
@ -1,4 +1,6 @@
|
|||||||
|
# This class represents <input type="checkbox">
|
||||||
class Mechanize::FormContent::CheckBox < Mechanize::FormContent::RadioButton
|
class Mechanize::FormContent::CheckBox < Mechanize::FormContent::RadioButton
|
||||||
|
# set checkbox checked
|
||||||
def check
|
def check
|
||||||
@checked = true
|
@checked = true
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# This class represents <input> elements in the form.
|
# This class represents <input> elements in the form.
|
||||||
class Mechanize::FormContent::Field
|
class Mechanize::FormContent::Field
|
||||||
|
|
||||||
# returns field's 'value' attribute
|
# returns field's 'value' attribute
|
||||||
property value : String?
|
property value : String?
|
||||||
# returns field's 'name' attribute
|
# returns field's 'name' attribute
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require "./option"
|
require "./option"
|
||||||
|
|
||||||
|
# This class represents <select multiple>
|
||||||
class Mechanize::FormContent::MultiSelectList
|
class Mechanize::FormContent::MultiSelectList
|
||||||
getter node : Lexbor::Node
|
getter node : Lexbor::Node
|
||||||
getter name : String
|
getter name : String
|
||||||
@ -18,32 +19,37 @@ class Mechanize::FormContent::MultiSelectList
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# set all options unchecked
|
||||||
def select_none
|
def select_none
|
||||||
@values = Array(String).new
|
@values = Array(String).new
|
||||||
options.each &.unselect
|
options.each &.unselect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# set all options checked
|
||||||
def select_all
|
def select_all
|
||||||
@values = Array(String).new
|
@values = Array(String).new
|
||||||
options.each &.select
|
options.each &.select
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns all checked options
|
||||||
def selected_options
|
def selected_options
|
||||||
options.select &.selected?
|
options.select &.selected?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add new values to options
|
||||||
def values=(new_values)
|
def values=(new_values)
|
||||||
select_none
|
select_none
|
||||||
new_values.each do |value|
|
new_values.each do |value|
|
||||||
option = options.find { |o| o.value == value }
|
option = options.find { |o| o.value == value }
|
||||||
if option.nil?
|
if option.nil?
|
||||||
@value.push(value)
|
@values.push(value)
|
||||||
else
|
else
|
||||||
option.select
|
option.select
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# return all option's values.
|
||||||
def values
|
def values
|
||||||
@values + selected_options.map &.value
|
@values + selected_options.map &.value
|
||||||
end
|
end
|
||||||
|
@ -30,6 +30,7 @@ class Mechanize::FormContent::Option
|
|||||||
@selected = !@selected
|
@selected = !@selected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns option checked or not
|
||||||
def selected?
|
def selected?
|
||||||
@selected
|
@selected
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# This class represents <input type="radio">
|
||||||
class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
|
class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
|
||||||
property :checked, :form
|
property :checked, :form
|
||||||
|
|
||||||
@ -7,19 +8,23 @@ class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
|
|||||||
super(node)
|
super(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# set radiobutton checked
|
||||||
def check
|
def check
|
||||||
uncheck_peers
|
uncheck_peers
|
||||||
@checked = true
|
@checked = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# set radiobutton checked
|
||||||
def uncheck
|
def uncheck
|
||||||
@checked = false
|
@checked = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# change radiobutton state checked or unchecked
|
||||||
def click
|
def click
|
||||||
checked ? uncheck : check
|
checked ? uncheck : check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns radiobutton checked or not
|
||||||
def checked?
|
def checked?
|
||||||
checked
|
checked
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require "./multi_select_list"
|
require "./multi_select_list"
|
||||||
|
|
||||||
|
# This class represents <select> which is not multiple
|
||||||
class Mechanize::FormContent::SelectList < Mechanize::FormContent::MultiSelectList
|
class Mechanize::FormContent::SelectList < Mechanize::FormContent::MultiSelectList
|
||||||
def initialize(node)
|
def initialize(node)
|
||||||
super node
|
super node
|
||||||
|
Loading…
Reference in New Issue
Block a user