Select

Select control

Parameters you can pass

ParameterData typeDescription
namestringName of input that will be used in the form
idintHidden input ID (stores the value)
itemsarray of objArray of select values
selectedintID of selected value from items array
class_namestringWrapper class (if several classes passed, divide them by Space)
button_class_namestringClass of the button that opens Select
input_special_classstringInput class
selected_beforestringText displayed before the value
disabledboolShows if it's disabled

Parameters of items

ParameterData typeDescription
idintID value, will be pasted into hidden input when selected by the user
optionstringValue (text)
class_namestringCustom class of Select element
bg_colorstringHEX code for the background color of the element ( e.g., used for lead stages)

To track changes in the selector value, you need to listen to the controls:change custom event.

$('.my-select-wrapper').on('controls:change', 'input', function (e) {
  var $input = $(e.currentTarget);

  console.log('Input value', $input.val());
});


Selected

self.render({ ref: '/tmpl/controls/select.twig' }, {
    name: 'animal',
    items: [
      { id: 1, option: 'Cat' },
      { id: 2, option: 'Dog' },
    ],
  selected: 1
  });

Text before the value


  self.render({ ref: '/tmpl/controls/select.twig' }, {
    name: 'animal',
    items: [
      { id: 1, option: 'Cat' },
      { id: 2, option: 'Dog' },
    ],
    selected_before: 'Favorite animal: ',
    selected: 2
  });