Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vunamhung/cmb2_select2
https://github.com/vunamhung/cmb2_select2
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/vunamhung/cmb2_select2
- Owner: vunamhung
- Created: 2020-02-04T07:28:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-11T23:24:13.000Z (over 3 years ago)
- Last Synced: 2024-11-15T19:06:42.080Z (about 2 months ago)
- Language: PHP
- Size: 79.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# CMB2 Field Type: Select2
## Description
[Select2](https://select2.github.io/) field type for [CMB2](https://github.com/WebDevStudios/CMB2 "Custom Metaboxes and Fields for WordPress 2").
This plugin gives you two additional field types based on Select2:
1. The `select2` field acts much like the default `select` field. However, it adds typeahead-style search allowing you to quickly make a selection from a large list
2. The `multiselect2` field allows you to select multiple values with typeahead-style search. The values can be dragged and dropped to reorder## Usage
`select2` - Select box with with typeahead-style search. Example:
```php
$cmb->add_field( array(
'name' => 'Cooking time',
'id' => $prefix . 'cooking_time',
'desc' => 'Cooking time',
'type' => 'select2',
'options' => array(
'5' => '5 minutes',
'10' => '10 minutes',
'30' => 'Half an hour',
'60' => '1 hour',
),
) );```
`multiselect2` - Multi-value select box with drag and drop reordering. Example:
```php
$cmb->add_field( array(
'name' => 'Ingredients',
'id' => $prefix . 'ingredients',
'desc' => 'Select ingredients. Drag to reorder.',
'type' => 'multiselect2',
'options' => array(
'flour' => 'Flour',
'salt' => 'Salt',
'eggs' => 'Eggs',
'milk' => 'Milk',
'butter' => 'Butter',
),
) );
```### Placeholder
You can specify placeholder text through the attributes array. Example:
```php
$cmb->add_field( array(
'name' => 'Ingredients',
'id' => $prefix . 'ingredients',
'desc' => 'Select this recipes ingredients.',
'type' => 'multiselect2',
'options' => array(
'flour' => 'Flour',
'salt' => 'Salt',
'eggs' => 'Eggs',
'milk' => 'Milk',
'butter' => 'Butter',
),
'attributes' => array(
'placeholder' => 'Select ingredients. Drag to reorder'
),
) );
```### Custom Select2 configuration and overriding default configuration options
You can define Select2 configuration options using HTML5 `data-*` attributes. It's worth reading up on the [available options](https://select2.github.io/options.html#data-attributes) over on the Select2 website. Example:
```php
$cmb->add_field( array(
'name' => 'Ingredients',
'id' => $prefix . 'ingredients',
'desc' => 'Select ingredients. Drag to reorder.',
'type' => 'multiselect2',
'options' => array(
'flour' => 'Flour',
'salt' => 'Salt',
'eggs' => 'Eggs',
'milk' => 'Milk',
'butter' => 'Butter',
),
'attributes' => array(
'data-maximum-selection-length' => '2',
),
) );
```