Class: Dommy::HTMLTextAreaElement

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

Overview

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

Constant Summary collapse

JS_METHOD_NAMES =

Own js_call methods, on top of Element’s.

%w[
  select setSelectionRange setRangeText checkValidity reportValidity setCustomValidity
].freeze

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

#document

Instance Method Summary collapse

Methods inherited from HTMLElement

#case_sensitive_attribute_names?

Methods inherited from Element

#[], #[]=, #__dommy_backend_node__, #__internal_shadow_root__, #__test_scroll_log__, #after, #anchor_href, #animate, #append, #append_child, #at_xpath, #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, #path, #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, #xpath

Methods included from EventTarget

#__internal_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



1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
# File 'lib/dommy/html_elements.rb', line 1790

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



1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
# File 'lib/dommy/html_elements.rb', line 1724

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_method_names__Object



1591
1592
1593
# File 'lib/dommy/html_elements.rb', line 1591

def __js_method_names__
  super + JS_METHOD_NAMES
end

#__js_set__(key, v) ⇒ Object



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

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



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

def autocomplete
  reflected_string("autocomplete")
end

#check_validityObject



1709
1710
1711
1712
1713
# File 'lib/dommy/html_elements.rb', line 1709

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

#colsObject



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

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

#cols=(v) ⇒ Object



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

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

#default_valueObject



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

def default_value
  text_content
end

#default_value=(v) ⇒ Object



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

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

#formObject



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

def form
  closest("form")
end

#labelsObject



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

def labels
  return [] if id.empty?

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

#max_lengthObject



1648
1649
1650
# File 'lib/dommy/html_elements.rb', line 1648

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

#min_lengthObject



1652
1653
1654
# File 'lib/dommy/html_elements.rb', line 1652

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

#nameObject



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

def name
  reflected_string("name")
end

#name=(v) ⇒ Object



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

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

#placeholderObject



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

def placeholder
  reflected_string("placeholder")
end

#placeholder=(v) ⇒ Object



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

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

#report_validityObject



1715
1716
1717
# File 'lib/dommy/html_elements.rb', line 1715

def report_validity
  check_validity
end

#rowsObject



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

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

#rows=(v) ⇒ Object



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

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

#selectObject

No real selection — same stub story as input.



1679
1680
1681
# File 'lib/dommy/html_elements.rb', line 1679

def select
  nil
end

#set_custom_validity(msg) ⇒ Object



1719
1720
1721
1722
# File 'lib/dommy/html_elements.rb', line 1719

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

#set_range_text(_replacement, *_) ⇒ Object



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

def set_range_text(_replacement, *_)
  nil
end

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



1683
1684
1685
# File 'lib/dommy/html_elements.rb', line 1683

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

#text_lengthObject



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

def text_length
  value.length
end

#typeObject



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

def type
  "textarea"
end

#validation_messageObject



1699
1700
1701
1702
1703
1704
1705
1706
1707
# File 'lib/dommy/html_elements.rb', line 1699

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



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

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

#valueObject



1595
1596
1597
# File 'lib/dommy/html_elements.rb', line 1595

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

#value=(v) ⇒ Object



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

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

#will_validateObject



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

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

#wrapObject



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

def wrap
  reflected_string("wrap")
end