PHP code example of db-web-solutions / drupal-tom-select

1. Go to this page and download the library: Download db-web-solutions/drupal-tom-select library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

db-web-solutions / drupal-tom-select example snippets


$form['example'] = [
  '#type' => 'select',
  '#title' => $this->t('Example'),
  '#options' => [
    'one' => $this->t('One'),
    'two' => $this->t('Two'),
  ],
  '#tom_select' => TRUE,
];

$form['example'] = [
  '#type' => 'select',
  '#title' => $this->t('Example'),
  '#options' => [
    'one' => $this->t('One'),
    'two' => $this->t('Two'),
  ],
  '#empty_option' => $this->t('- Select -'),
  '#tom_select' => TRUE,
  '#tom_select_options' => [
    'allowEmptyOption' => TRUE,
  ],
];

$form['tags'] = [
  '#type' => 'select',
  '#title' => $this->t('Tags'),
  '#multiple' => TRUE,
  '#options' => [
    'summer' => $this->t('Summer'),
    'winter' => $this->t('Winter'),
    'all-season' => $this->t('All season'),
  ],
  '#tom_select' => TRUE,
  '#tom_select_options' => [
    'plugins' => ['remove_button'],
  ],
];

$form['example'] = tom_select_attach($form['example'], [
  'allowEmptyOption' => TRUE,
]);

'#tom_select' => TRUE,