Class: Dommy::HTMLFormControlsCollection
- Inherits:
-
HTMLCollection
- Object
- HTMLCollection
- Dommy::HTMLFormControlsCollection
- Defined in:
- lib/dommy/html_collection.rb
Overview
HTMLFormControlsCollection — a form's elements. Like HTMLCollection but
its named getter returns a RadioNodeList when a name/id matches more than one
control (e.g. a radio group), and the single control otherwise.
Constant Summary
Constants inherited from HTMLCollection
Dommy::HTMLCollection::HTML_NAMESPACE
Instance Method Summary collapse
-
#controls_named(key) ⇒ Object
The controls in this collection whose id or name equals
key, in order. - #named_item(name) ⇒ Object
Methods inherited from HTMLCollection
#[], #__js_call__, #__js_get__, #__js_named_props__, ascii_downcase, #each, elements_by_tag_name, elements_by_tag_name_ns, #empty?, #first, #initialize, #item, #last, #length, qualified_name_of, #to_a
Methods included from Bridge::Methods
Constructor Details
This class inherits a constructor from Dommy::HTMLCollection
Instance Method Details
#controls_named(key) ⇒ Object
The controls in this collection whose id or name equals key, in order.
247 248 249 250 251 252 253 254 |
# File 'lib/dommy/html_collection.rb', line 247 def controls_named(key) to_a.select do |el| next false unless el.respond_to?(:__dommy_backend_node__) node = el.__dommy_backend_node__ node["id"].to_s == key || node["name"].to_s == key end end |
#named_item(name) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/dommy/html_collection.rb', line 232 def named_item(name) key = name.to_s return nil if key.empty? matches = controls_named(key) return nil if matches.empty? return matches.first if matches.length == 1 # A live RadioNodeList: a reference held across a DOM mutation reflects the # updated group (per spec the named getter returns a live NodeList). coll = self RadioNodeList.new(matches) { coll.controls_named(key) } end |