new Toggle(options) → {Class}
A toggle component to use wherever boolean based form fields are needed.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | object | The options for the component. Properties
|
- Since
- 1.1.16
- Source
The class instance.
- Type:
- Class
import Toggle from '@gravityforms/components/html/admin/elements/Toggle';
function Example() {
const toggleInstance = new Toggle( {
id: 'example-toggle',
label: 'Example Toggle',
name: 'example-toggle',
renderOnInit: false,
target: '#example-target',
targetPosition: 'beforeend',
theme: 'cosmos',
} );
// Some time later we can render it. This is only done if we set renderOnInit to false.
// If true it will render on initialization.
toggleInstance.init();
}
Methods
(static) init() → {void}
Initialize the component.
- Since
- 1.1.16
- Source
- Type:
- void
(static) render() → {void}
Renders the component into the dom.
- Since
- 1.1.16
- Source
- Type:
- void
(static) toggleTemplate(options) → {string}
Generates the markup for a toggle in the admin.
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | object | The options for the component template. Properties
|
- Since
- 1.1.16
- Source
- Type:
- string
import { toggleTemplate } from '@gravityforms/components/html/admin/elements/Toggle';
function Example() {
const toggleHTML = toggleTemplate( options );
document.body.insertAdjacentHTML( 'beforeend', toggleHTML );
}