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
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/vapir-common/elements/elements.rb', line 180 def append(value, ={}) raise ArgumentError, "Text field value must be a string! Got #{value.inspect}" unless value.is_a?(String) ={:blur => true, :change => true, :select => true, :focus => true}.merge() assert_enabled assert_not_readonly with_highlight() do existing_value_chars=element_object.value.split(//u) new_value_chars=existing_value_chars+value.split(//u) # IE treats the string value is set to as utf8, and this is consistent with String#ord defined in core_ext 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 if [:focus] assert_exists(:force => true) element_object.focus fire_event('onFocus') end if [:select] assert_exists(:force => true) element_object.select fire_event("onSelect") end if config.type_keys (existing_value_chars.length...new_value_chars.length).each do |i| last_key = (i == new_value_chars.length - 1) handling_existence_failure(:handle => (last_key ? :ignore : :raise)) do type_key(new_value_chars[i]) do assert_exists(:force => true) element_object.value = new_value_chars[0..i].join('') end end sleep config.typing_interval end else with_key_down do # simulate at least one keypress assert_exists(:force => true) element_object.value = new_value_chars.join('') end end if [:change] && exists? handling_existence_failure { fire_event("onChange") } end if [:blur] && exists? handling_existence_failure { fire_event('onBlur') } end wait exists? ? self.value : nil 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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/vapir-common/elements/elements.rb', line 101 def clear(={}) ={:blur => true, :change => true, :select => true, :focus => true}.merge() assert_enabled assert_not_readonly with_highlight() do if [:focus] assert_exists(:force => true) element_object.focus fire_event('onFocus') end if [:select] assert_exists(:force => true) element_object.select fire_event("onSelect") end handling_existence_failure do with_key_down(:keyCode => KeyCodes[:delete]) do assert_exists(:force => true) element_object.value = '' end end if [:change] && exists? fire_event("onChange") end if [:blur] && exists? fire_event('onBlur') end exists? ? self.value : nil 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
241 242 243 244 245 246 |
# File 'lib/vapir-common/elements/elements.rb', line 241 def set(value, ={}) with_highlight() do clear(.merge(:blur => false, :change => false)) append(value, .merge(:focus => false, :select => false)) end end |