CorvidReference

ValueMixin

Adds the value property to elements.

Table of Contents

PROPERTIES

?
Store values associated with an object.
valueSets or gets an element's value.

FUNCTIONS

?
Perform actions on an object.
onChange( )

Adds an event handler that runs when an input element's value is changed.

value

Sets or gets an element's value.

Description

The value property's type depends on the element implementing it.

Note

Changing an element's value in code does not trigger an onChange event.

If an element is connected to a dataset, setting the element's value in code does not set the value of the connected field in the dataset. That means if you use the dataset to perform a submit, the value changed in code is not reflected in the submitted item.

To submit the new value using a dataset, set the field's value using the setFieldValue() function before performing the submit.

Syntax

get value(): *
set value(value: *): void
TYPE
?
The kind of data the property stores.
*

Examples

Get an element's value

let myValue = $w("#myElement").value; // "42"

Set an element's value

$w("#myElement").value = "42";

onChange( )

Adds an event handler that runs when an input element's value is changed.

Description

An element receives a change event when a user changes the value in an input element.

A change event is not triggered when you change an element's value using the element's value property.

Note

Deprecation note: The $w parameter of event handlers is being deprecated. To get a scoped selector for working with elements in repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context). To learn more, see here.

Syntax

function onChange(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
PARAMETERS
?
Values that you pass to a function.
handler
function(event: Event, $w: $w)

The name of the function or the function expression to run when the element's value changes.

?
Values that you pass to a function.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function was used to enable event handlers to work with elements in repeaters. Now, to get a scoped selector for working with repeater items, use the $w.at() function and pass it the context property of the event parameter: $item = $w.at(event.context).

RETURN VALUE
?
Value that a function evaluates to when it is finished running.
The element on which the event is now registered.

Examples

Get the value of the element that was changed

$w("#myElement").onChange( (event) => {
  let newValue = event.target.value;  // "new value"
});