CodeAPI

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

To reset the form element's value, set the value property to null or undefined.

Note

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(): string
set value(value: string): void
TYPE
?
The kind of data the property stores.
string

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, 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
?
The kind of data the property stores.
handler
function(event: Event, $w: $w)

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

?
The kind of data the property stores.
event
The event that occurred.
$w

Deprecated: A selector function. The $w function enables event handlers to work with elements in repeaters and in the global scope.

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"
});