$w.RequiredMixin

$w.RequiredMixin

Provides functionality for input elements can be required to have a value.

Contents

required Sets or gets whether an input element is required to have a value.
required

required

Sets or gets whether an input element is required to have a value.

Syntax

get required(): boolean
set required(value: boolean): void

Description

Setting the required property to true causes the element to be invalid if it doesn't contain a value. Setting it to false allows the element to be valid even if it doesn't contain a value. The validity of the element can be checked using its validity property.

Getting the value of the required property returns whether the element is required.

You can also set an input element to be required by using the element's Settings pane in the Editor.

Type

Boolean

Examples

Set an element to be required

JHcoIiNteUVsZW1lbnQiKS5yZXF1aXJlZCA9IHRydWU7Cg==
$w("#myElement").required = true;

Get whether an element is required

bGV0IGlzUmVxdWlyZWQgPSAkdygiI215RWxlbWVudCIpLnJlcXVpcmVkOyAvLyB0cnVlCg==
let isRequired = $w("#myElement").required; // true

See Also

validity