wip add radiobuttons
parent
83f390bd2a
commit
6ccb70dcb7
|
@ -1,9 +1,11 @@
|
|||
require "./form/field"
|
||||
require "./form/check_box"
|
||||
require "./form/radio_button"
|
||||
|
||||
class MechanizeCr::Form
|
||||
getter fields : Array(FormContent::Field)
|
||||
getter checkboxes : Array(FormContent::CheckBox)
|
||||
getter radiobuttons : Array(FormContent::RadioButton)
|
||||
getter enctype : String
|
||||
getter method : String
|
||||
getter name : String
|
||||
|
@ -14,6 +16,7 @@ class MechanizeCr::Form
|
|||
@node = node
|
||||
@fields = Array(FormContent::Field).new
|
||||
@checkboxes = Array(FormContent::CheckBox).new
|
||||
@radiobuttons = Array(FormContent::RadioButton).new
|
||||
@action = node.fetch("action", "")
|
||||
@method = node.fetch("method", "GET").upcase
|
||||
@name = node.fetch("name", "")
|
||||
|
|
|
@ -1,29 +1,8 @@
|
|||
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
|
||||
property :checked, :form
|
||||
|
||||
def initialize(node : Node | Myhtml::Node, form : Form)
|
||||
@checked = !!node["checked"]
|
||||
@form = form
|
||||
super(node)
|
||||
end
|
||||
|
||||
require "./radio_button"
|
||||
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::RadioButton
|
||||
def check
|
||||
#uncheck_peers
|
||||
@checked = true
|
||||
end
|
||||
|
||||
def uncheck
|
||||
@checked = false
|
||||
end
|
||||
|
||||
def checked?
|
||||
checked
|
||||
end
|
||||
|
||||
def click
|
||||
checked ? uncheck : check
|
||||
end
|
||||
|
||||
def query_value
|
||||
[@name, @value || "on"]
|
||||
end
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
class MechanizeCr::FormContent::RadioButton < MechanizeCr::FormContent::Field
|
||||
property :checked, :form
|
||||
|
||||
def initialize(node : Node | Myhtml::Node, form : Form)
|
||||
@checked = !!node["checked"]
|
||||
@form = form
|
||||
super(node)
|
||||
end
|
||||
|
||||
def check
|
||||
#uncheck_peers
|
||||
@checked = true
|
||||
end
|
||||
|
||||
def uncheck
|
||||
@checked = false
|
||||
end
|
||||
|
||||
def click
|
||||
checked ? uncheck : check
|
||||
end
|
||||
|
||||
def checked?
|
||||
checked
|
||||
end
|
||||
|
||||
#def hash # :nodoc:
|
||||
# @form.hash ^ @name.hash ^ @value.hash
|
||||
#end
|
||||
#
|
||||
#def label
|
||||
# (id = self['id']) && @form.page.labels_hash[id] || nil
|
||||
#end
|
||||
#
|
||||
#def text
|
||||
# label.text rescue nil
|
||||
#end
|
||||
#
|
||||
#def [](key)
|
||||
# @node[key]
|
||||
#end
|
||||
|
||||
# alias checked? checked
|
||||
|
||||
#def == other # :nodoc:
|
||||
# self.class === other and
|
||||
# other.form == @form and
|
||||
# other.name == @name and
|
||||
# other.value == @value
|
||||
#end
|
||||
#
|
||||
#alias eql? == # :nodoc:
|
||||
|
||||
|
||||
#private def uncheck_peers
|
||||
# @form.radiobuttons_with(:name => name).each do |b|
|
||||
# next if b.value == value
|
||||
# b.uncheck
|
||||
# end
|
||||
#end
|
||||
|
||||
end
|
Loading…
Reference in New Issue