Select

new Select(options) → {Class}

A select component to use wherever a simple select is needed.

Parameters:
NameTypeDescription
optionsobject

Component options.

Properties
NameTypeDescription
customAttributesobject

Custom attributes for the component.

customClassesstring | Array | object

Custom classes for the component.

disabledboolean

If select is disabled.

helpTextAttributesstring

Custom attribute for the help text.

helpTextPositionstring

The position of the help text. Above or below.

idstring

Optional id. Auto generated if not passed.

initialValuestring

Initial value for the select.

labelAttributesstring

Any custom attributes for the label.

namestring

The name attribute for the select.

optionsArray

An array of options, each option as an object in the following structure: { customOptionAttrs: {}, // Key-value pairs of custom attributes. customOptionClasses: [], // Array of strings of custom classes. label: '', // Label as a string. value: '', // Value as a string. }

sizestring

The select size. Regular (size-r) or extra large (size-xl).

renderedboolean

Is this select already rendered in the dom, eg by php?

renderOnInitboolean

Render the select on init of the class?

spacingstring | number | Array | object

The spacing for the component, as a string, number, array, or object.

themestring

The theme of the select.

targetstring

The target to render to. Any valid css selector string.

targetPositionstring

The insert position for the target.

wrapperAttributesobject

Custom attributes for the wrapper element.

wrapperClassesstring | Array | object

Custom classes for the wrapper element.

wrapperTagNameobject

Tag to use for the textarea wrapper. Defaults to div.

ariaLabelstring

The aria-label text for the select element.

Since
  • 2.2.0
Returns:

The select instance.

Type: 
Class
Example
import Select from '@gravityforms/components/html/admin/elements/Select';

function Example() {
     const selectInstance = new Select( {
         name: 'select-name'
         options: { [
            {
                label: 'Option 1',
                value: 'option-1',
            },
            {
                label: 'Option 2',
                value: 'option-2',
            },
            {
                label: 'Option 3',
                value: 'option-3',
            },
        ] },
        target: '#select-target'
     } );
}