Module: Vapir::TextField
- Extended by:
- ElementHelper
- Defined in:
- lib/vapir-common/elements/elements.rb
Instance Method Summary collapse
-
#append(value, options = {}) ⇒ Object
Appends the specified string value to the contents of the text box.
-
#clear(options = {}) ⇒ Object
Clears the contents of the text field.
-
#set(value, options = {}) ⇒ Object
Sets the contents of the text field to the given value.
Methods included from ElementHelper
add_specifier, container_collection_method, container_single_method, included
Methods included from ElementClassAndModuleMethods
#add_container_method_extra_args, #all_dom_attr_aliases, #all_dom_attrs, #class_array_append, #class_array_get, #class_hash_get, #class_hash_merge, #container_collection_methods, #container_method_extra_args, #container_single_methods, #default_how, #dom_attr, #dom_attr_locate_alias, #dom_function, #dom_setter, #element_collection, #factory, #inspect_these, #inspect_this_if, #parent_element_module, #set_or_get_class_var, #specifiers
Instance Method Details
#append(value, options = {}) ⇒ Object
Appends the specified string value to the contents of the text box.
returns the new value of the text field. this may not include all of what is given if there is a maxlength on the field.
takes options: :blur => true/false; whether or not to file the onblur event when done. :highlight => true/false
Raises UnknownObjectException if the object cant be found
Raises ObjectDisabledException if the object is disabled
Raises ObjectReadOnlyException if the object is read only
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/vapir-common/elements/elements.rb', line 124 def append(value, ={}) ={:blur => true, :change => true, :select => true, :focus => true}.merge() assert_enabled assert_not_readonly with_highlight() do existing_value_chars=element_object.value.split(//) new_value_chars=existing_value_chars+value.split(//) #value_chars=value.split(//) # split on blank regexp (rather than iterating over each byte) for multibyte chars if self.type.downcase=='text' && maxlength && maxlength >= 0 && new_value_chars.length > maxlength new_value_chars=new_value_chars[0...maxlength] end element_object.scrollIntoView type_keys=respond_to?(:type_keys) ? self.type_keys : true # TODO: FIX typingspeed=respond_to?(:typingspeed) ? self.typingspeed : 0 # TODO: FIX if type_keys if [:focus] element_object.focus fire_event('onFocus') assert_exists(:force => true) end if [:select] element_object.select fire_event("onSelect") assert_exists(:force => true) end ((existing_value_chars.length)...new_value_chars.length).each do |i| # sleep typingspeed # TODO/FIX element_object.value = new_value_chars[0..i].join('') fire_event :onKeyDown # TODO/fix - keyCode for character typed assert_exists(:force => true) fire_event :onKeyPress assert_exists(:force => true) fire_event :onKeyUp assert_exists(:force => true) end if [:change] && exists? fire_event("onChange") end if [:blur] && exists? fire_event('onBlur') end else element_object.value = element_object.value + value end wait self.value end end |
#clear(options = {}) ⇒ Object
Clears the contents of the text field.
to be consistent with similar methods #set and #append, returns the new value, though this will always be a blank string.
takes options: :blur => true/false; whether or not to fire the onblur event when done. :highlight => true/false
Raises UnknownObjectException if the object can't be found
Raises ObjectDisabledException if the object is disabled
Raises ObjectReadOnlyException if the object is read only
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vapir-common/elements/elements.rb', line 82 def clear(={}) ={:blur => true, :change => true, :select => true, :focus => true}.merge() assert_enabled assert_not_readonly with_highlight() do if [:focus] element_object.focus fire_event('onFocus') assert_exists(:force => true) end if [:select] element_object.select fire_event("onSelect") assert_exists(:force => true) end element_object.value = '' fire_event :onKeyDown # TODO/fix - keyCode for 'delete' key assert_exists(:force => true) fire_event :onKeyPress assert_exists(:force => true) fire_event :onKeyUp assert_exists(:force => true) if [:change] && exists? fire_event("onChange") end if [:blur] && exists? fire_event('onBlur') end self.value end end |
#set(value, options = {}) ⇒ Object
Sets the contents of the text field to the given value
returns the new value of the text field. this may be shorter than what is given if there is a maxlength on the field.
takes options: :blur => true/false; whether or not to file the onblur event when done. :highlight => true/false
Raises UnknownObjectException if the object cant be found
Raises ObjectDisabledException if the object is disabled
Raises ObjectReadOnlyException if the object is read only
184 185 186 187 188 189 190 191 |
# File 'lib/vapir-common/elements/elements.rb', line 184 def set(value, ={}) with_highlight() do clear(.merge(:blur => false, :change => false)) assert_exists(:force => true) append(value, .merge(:focus => false, :select => false)) self.value end end |