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