Form.Element

This is a collection of methods that assist in dealing with form controls. They provide ways to focus, serialize, disable/enable or extract current value from a specific control.

 

In Prototype, Form.Element is also aliased Field and all these methods are available directly on INPUT, SELECT and TEXTAREA elements that have been extended (see “How Prototype extends the DOM”). Therefore, these are equivalent:

 

·Form.Element.activate('myfield')

 

·Field.activate('myfield')

 

·$('myfield').activate()

 

Naturally, you should always prefer the shortest form suitable in a situation. Most of these methods also return the element itself (as indicated by the return type) for chainability.

 

activate

 

activate(element) -> HTMLElement

 

Gives focus to a form control and selects its contents if it is a text input.

 

clear

 

clear(element) -> HTMLElement

 

Clears the contents of a text input.

 

disable

 

disable(element) -> HTMLElement

 

Disables a form control, effectively preventing its value to be changed until it is enabled again.

 

enable

 

enable(element) -> HTMLElement

 

Enables a previously disabled form control.

 

focus

 

focus(element) -> HTMLElement

 

Gives keyboard focus to an element.

 

getValue

 

getValue(element) -> string | array

 

Returns the current value of a form control. A string is returned for most controls; only multiple select boxes return an array of values. The global shortcut for this method is $F().

 

present

 

present(element) -> boolean

 

Returns true if a text input has contents, false otherwise.

 

select

 

select(element) -> HTMLElement

 

Selects the current text in a text input.

 

serialize

 

serialize(element) -> string

 

Creates an URL-encoded string representation of a form control in the name=value format.

 

 

 


Prototype API 1.5.0 - prototypejs.org