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 Element

#[], #[]=, #__shadow_root__, #after, #anchor_href, #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_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



1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
# File 'lib/dommy/html_elements.rb', line 1778

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



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
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/dommy/html_elements.rb', line 1712

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



1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
# File 'lib/dommy/html_elements.rb', line 1753

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



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

def autocomplete
  reflected_string("autocomplete")
end

#check_validityObject



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

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

#colsObject



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

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

#cols=(v) ⇒ Object



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

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

#default_valueObject



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

def default_value
  text_content
end

#default_value=(v) ⇒ Object



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

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

#formObject



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

def form
  closest("form")
end

#labelsObject



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

def labels
  return [] if id.empty?

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

#max_lengthObject



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

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

#min_lengthObject



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

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

#nameObject



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

def name
  reflected_string("name")
end

#name=(v) ⇒ Object



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

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

#placeholderObject



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

def placeholder
  reflected_string("placeholder")
end

#placeholder=(v) ⇒ Object



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

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

#report_validityObject



1703
1704
1705
# File 'lib/dommy/html_elements.rb', line 1703

def report_validity
  check_validity
end

#rowsObject



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

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

#rows=(v) ⇒ Object



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

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

#selectObject

No real selection — same stub story as input.



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

def select
  nil
end

#set_custom_validity(msg) ⇒ Object



1707
1708
1709
1710
# File 'lib/dommy/html_elements.rb', line 1707

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

#set_range_text(_replacement, *_) ⇒ Object



1675
1676
1677
# File 'lib/dommy/html_elements.rb', line 1675

def set_range_text(_replacement, *_)
  nil
end

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



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

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

#text_lengthObject



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

def text_length
  value.length
end

#typeObject



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

def type
  "textarea"
end

#validation_messageObject



1687
1688
1689
1690
1691
1692
1693
1694
1695
# File 'lib/dommy/html_elements.rb', line 1687

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



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

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

#valueObject



1583
1584
1585
# File 'lib/dommy/html_elements.rb', line 1583

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

#value=(v) ⇒ Object



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

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

#will_validateObject



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

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

#wrapObject



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

def wrap
  reflected_string("wrap")
end