Skip to main content

getValue()

returns the current value/state of a Toggle control

getValue(): string | number| boolean;

Returns:

Either a string/number with the current value of the control or a boolean value with the state of the control.

Example

// returns a value if the value is specified for the toggle
const value = form.getItem("toggle").getValue(); // -> "toggle_value"

// returns a state if the value is not specified for the toggle
const state = form.getItem("toggle").getValue(); // -> true/false
  • If the value property is not set for a control, the method returns the state of the control:
const form = new dhx.Form("form_container", {
rows: [
{
name: "toggle",
type: "toggle",
icon: "dxi dxi-eye",
offIcon: "dxi dxi-eye-off",
text: "Visible",
offText: "Invisible",
selected: true
}
]
});

const state = form.getItem("toggle").getValue(); // -> true/false
  • If the value property is defined, the method returns a string/number value. In addition, if the selected option is set to true, the method returns the value of a control, otherwise - returns an empty string (""):
const form = new dhx.Form("form_container", {
rows: [
{
name: "toggle",
type: "toggle",
icon: "dxi dxi-eye",
offIcon: "dxi dxi-eye-off",
text: "Visible",
offText: "Invisible",
selected: false,
value: "toggle_value"
}
]
});

const value = form.getItem("toggle").getValue(); // -> ""