Class: Dommy::HTMLTextAreaElement

Inherits:
HTMLElement show all
Defined in:
lib/dommy/html_elements.rb

Overview

‘<textarea>` — multi-line text input.

Constant Summary

Constants inherited from Element

Element::ATTRIBUTE_NODE, Element::CDATA_SECTION_NODE, Element::COMMENT_NODE, Element::DOCUMENT_FRAGMENT_NODE, Element::DOCUMENT_NODE, Element::DOCUMENT_POSITION_CONTAINED_BY, Element::DOCUMENT_POSITION_CONTAINS, Element::DOCUMENT_POSITION_DISCONNECTED, Element::DOCUMENT_POSITION_FOLLOWING, Element::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Element::DOCUMENT_POSITION_PRECEDING, Element::DOCUMENT_TYPE_NODE, Element::ELEMENT_NODE, Element::PROCESSING_INSTRUCTION_NODE, Element::SHADOW_HOST_TAGS, Element::TEXT_NODE

Constants included from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_POSITION_CONTAINED_BY, Node::DOCUMENT_POSITION_CONTAINS, Node::DOCUMENT_POSITION_DISCONNECTED, Node::DOCUMENT_POSITION_FOLLOWING, Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Node::DOCUMENT_POSITION_PRECEDING, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Attribute Summary

Attributes inherited from Element

#__node__, #document

Instance Method Summary collapse

Methods inherited from HTMLElement

#case_sensitive_attribute_names?

Methods inherited from Element

#[], #[]=, #__scroll_log__, #__shadow_root__, #after, #anchor_href, #animate, #append, #append_child, #attach_shadow, #attributes, #base_uri, #before, #blur, #child_element_count, #child_nodes, #children, #class_list, #class_name, #class_name=, #click, #clone_node, #closest, #compare_document_position, #contains?, #dataset, #equal_node?, #first_child, #first_element_child, #focus, #get_animations, #get_attribute, #get_attribute_node, #get_elements_by_class_name, #get_elements_by_tag_name, #get_html, #get_inner_html, #has_attribute?, #has_attributes?, #has_child_nodes?, #id, #id=, #initialize, #inner_html, #inner_html=, #insert_adjacent_element, #insert_adjacent_html, #insert_adjacent_text, #insert_before, #is_connected?, #last_child, #last_element_child, #live_child_nodes, #local_name, #matches?, #namespace_uri, #next_element_sibling, #next_sibling, #normalize, #on, #outer_html, #outer_html=, #owner_document, #parent_element, #parent_node, #prepend, #previous_element_sibling, #previous_sibling, #query_selector, #query_selector_all, #reflected_attr_name, #remove, #remove_attribute, #remove_attribute_node, #remove_child, #replace_child, #replace_children, #replace_with_nodes, #role, #role=, #root_node, #same_node?, #set_attribute, #set_attribute_node, #shadow_root, #slot, #slot=, #style, #tag_name, #text_content, #text_content=, #to_s, #toggle_attribute

Methods included from EventTarget

#__deliver_event__, #add_event_listener, #dispatch_event, #invoke_listener, #remove_event_listener

Constructor Details

This class inherits a constructor from Dommy::Element

Instance Method Details

#__js_call__(method, args) ⇒ Object



1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
# File 'lib/dommy/html_elements.rb', line 1767

def __js_call__(method, args)
  case method
  when "select"
    select
  when "setSelectionRange"
    set_selection_range(args[0], args[1], args[2])
  when "setRangeText"
    set_range_text(args[0])
  when "checkValidity"
    check_validity
  when "reportValidity"
    report_validity
  when "setCustomValidity"
    set_custom_validity(args[0])
  else
    super
  end
end

#__js_get__(key) ⇒ Object



1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
# File 'lib/dommy/html_elements.rb', line 1701

def __js_get__(key)
  case key
  when "value"
    value
  when "defaultValue"
    default_value
  when "name"
    name
  when "placeholder"
    placeholder
  when "rows"
    rows
  when "cols"
    cols
  when "wrap"
    wrap
  when "maxLength"
    max_length
  when "minLength"
    min_length
  when "textLength"
    text_length
  when "autocomplete"
    autocomplete
  when "type"
    type
  when "form"
    form
  when "labels"
    labels
  when "validity"
    validity
  when "willValidate"
    will_validate
  when "validationMessage"
    validation_message
  else
    super
  end
end

#__js_set__(key, v) ⇒ Object



1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
# File 'lib/dommy/html_elements.rb', line 1742

def __js_set__(key, v)
  case key
  when "value"
    self.value = v
  when "defaultValue"
    self.default_value = v
  when "name"
    set_reflected_string("name", v)
  when "placeholder"
    set_reflected_string("placeholder", v)
  when "rows"
    self.rows = v
  when "cols"
    self.cols = v
  when "wrap"
    set_reflected_string("wrap", v)
  when "maxLength"
    set_reflected_string("maxlength", v.to_s)
  when "minLength"
    set_reflected_string("minlength", v.to_s)
  else
    super
  end
end

#autocompleteObject



1637
1638
1639
# File 'lib/dommy/html_elements.rb', line 1637

def autocomplete
  reflected_string("autocomplete")
end

#check_validityObject



1686
1687
1688
1689
1690
# File 'lib/dommy/html_elements.rb', line 1686

def check_validity
  ok = !will_validate || validity.valid
  dispatch_event(Event.new("invalid", "bubbles" => false, "cancelable" => true)) unless ok
  ok
end

#colsObject



1613
1614
1615
# File 'lib/dommy/html_elements.rb', line 1613

def cols
  (@__node__["cols"] || "20").to_i
end

#cols=(v) ⇒ Object



1617
1618
1619
# File 'lib/dommy/html_elements.rb', line 1617

def cols=(v)
  set_reflected_string("cols", v.to_s)
end

#default_valueObject



1581
1582
1583
# File 'lib/dommy/html_elements.rb', line 1581

def default_value
  text_content
end

#default_value=(v) ⇒ Object



1585
1586
1587
# File 'lib/dommy/html_elements.rb', line 1585

def default_value=(v)
  self.text_content = v
end

#formObject



1645
1646
1647
# File 'lib/dommy/html_elements.rb', line 1645

def form
  closest("form")
end

#labelsObject



1649
1650
1651
1652
1653
# File 'lib/dommy/html_elements.rb', line 1649

def labels
  return [] if id.empty?

  @document.query_selector_all("label[for='#{id}']")
end

#max_lengthObject



1625
1626
1627
# File 'lib/dommy/html_elements.rb', line 1625

def max_length
  (@__node__["maxlength"] || "-1").to_i
end

#min_lengthObject



1629
1630
1631
# File 'lib/dommy/html_elements.rb', line 1629

def min_length
  (@__node__["minlength"] || "-1").to_i
end

#nameObject



1589
1590
1591
# File 'lib/dommy/html_elements.rb', line 1589

def name
  reflected_string("name")
end

#name=(v) ⇒ Object



1593
1594
1595
# File 'lib/dommy/html_elements.rb', line 1593

def name=(v)
  set_reflected_string("name", v)
end

#placeholderObject



1597
1598
1599
# File 'lib/dommy/html_elements.rb', line 1597

def placeholder
  reflected_string("placeholder")
end

#placeholder=(v) ⇒ Object



1601
1602
1603
# File 'lib/dommy/html_elements.rb', line 1601

def placeholder=(v)
  set_reflected_string("placeholder", v)
end

#report_validityObject



1692
1693
1694
# File 'lib/dommy/html_elements.rb', line 1692

def report_validity
  check_validity
end

#rowsObject



1605
1606
1607
# File 'lib/dommy/html_elements.rb', line 1605

def rows
  (@__node__["rows"] || "2").to_i
end

#rows=(v) ⇒ Object



1609
1610
1611
# File 'lib/dommy/html_elements.rb', line 1609

def rows=(v)
  set_reflected_string("rows", v.to_s)
end

#selectObject

No real selection — same stub story as input.



1656
1657
1658
# File 'lib/dommy/html_elements.rb', line 1656

def select
  nil
end

#set_custom_validity(msg) ⇒ Object



1696
1697
1698
1699
# File 'lib/dommy/html_elements.rb', line 1696

def set_custom_validity(msg)
  @custom_validity_message = msg.to_s
  nil
end

#set_range_text(_replacement, *_) ⇒ Object



1664
1665
1666
# File 'lib/dommy/html_elements.rb', line 1664

def set_range_text(_replacement, *_)
  nil
end

#set_selection_range(_s, _e, _direction = nil) ⇒ Object



1660
1661
1662
# File 'lib/dommy/html_elements.rb', line 1660

def set_selection_range(_s, _e, _direction = nil)
  nil
end

#text_lengthObject



1633
1634
1635
# File 'lib/dommy/html_elements.rb', line 1633

def text_length
  value.length
end

#typeObject



1641
1642
1643
# File 'lib/dommy/html_elements.rb', line 1641

def type
  "textarea"
end

#validation_messageObject



1676
1677
1678
1679
1680
1681
1682
1683
1684
# File 'lib/dommy/html_elements.rb', line 1676

def validation_message
  return "" unless will_validate

  msg = (@custom_validity_message || "").to_s
  return msg unless msg.empty?
  return "Please fill out this field." if validity.value_missing

  ""
end

#validityObject



1668
1669
1670
# File 'lib/dommy/html_elements.rb', line 1668

def validity
  @__validity ||= ValidityState.new(self)
end

#valueObject



1572
1573
1574
# File 'lib/dommy/html_elements.rb', line 1572

def value
  @__node__["value"] || text_content
end

#value=(v) ⇒ Object



1576
1577
1578
1579
# File 'lib/dommy/html_elements.rb', line 1576

def value=(v)
  @__node__["value"] = v.to_s
  self.text_content = v.to_s
end

#will_validateObject



1672
1673
1674
# File 'lib/dommy/html_elements.rb', line 1672

def will_validate
  !reflected_boolean("disabled") && !reflected_boolean("readonly")
end

#wrapObject



1621
1622
1623
# File 'lib/dommy/html_elements.rb', line 1621

def wrap
  reflected_string("wrap")
end