PHP code example of computy / yii2-chipselect

1. Go to this page and download the library: Download computy/yii2-chipselect 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/ */

    

computy / yii2-chipselect example snippets


computy\chipselect\widgets\ChipSelect::widget([
    /*
    The ID is only used if no ID is set in the $containerOptions, in order to generate a container ID.
    If this is not set, this defaults to chip_select_ and a random integer.
    */
    'id' => 'my_cool_input',
    /*
    The name for the hidden inputs generated by the widget. '[]' is automatically appended to it.
    This must be set, otherwise an InvalidConfigException is thrown.
    */
    'name' => 'myCoolInput',
    /*
    The values to provide for the chip select, provided as a mapping from the actual value to the displayed name.
    */
    'data' => [
        1 => 'Option One',
        'two' => 'Option Two'
    ],
    /*
    The initial selected options.
    */
    'value' => [1],
    /*
    JavaScript logic to run whenever a chip is selected or deselected.
    This can alternatively be a `yii\web\JsExpression`.
    */
    'jsOnChange' => <<<JS
    () => {
        const selected = $('input[name="myCoolInput[]"]:not(:disabled)')
            .toArray()
            .map((elem) => elem.val())
            .join(', ')
        console.log(selected)
    }
    JS,
    /*
    HTML options to apply to the selectable items.
    */
    'options' => [
        'class' => 'my-chip'
    ],
    /*
    HTML options to apply to the hidden inputs.
    */
    'inputOptions' => [
        'class' => 'my-secret-input'
    ],
    /*
    HTML options to apply to the object containing the chip select.
    */
    'containerOptions' => [
        'class' => 'my-chipselect-container'
    ],
])