Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/awran5/cmb2-conditional-logic
A small jQuery plugin for handling conditional logic fields for CMB2.
https://github.com/awran5/cmb2-conditional-logic
cmb2 cmb2-conditionals jquery-plugin wordpress-plugin
Last synced: 16 days ago
JSON representation
A small jQuery plugin for handling conditional logic fields for CMB2.
- Host: GitHub
- URL: https://github.com/awran5/cmb2-conditional-logic
- Owner: awran5
- License: gpl-2.0
- Created: 2018-04-18T12:54:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-04T15:00:21.000Z (over 3 years ago)
- Last Synced: 2024-10-03T15:54:55.156Z (about 1 month ago)
- Topics: cmb2, cmb2-conditionals, jquery-plugin, wordpress-plugin
- Language: JavaScript
- Size: 21.5 KB
- Stars: 14
- Watchers: 2
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CMB2 conditional logic
A small jQuery plugin for handling conditional logic fields for [CMB2](https://github.com/CMB2/CMB2).
I used to use [cmb2-conditionals](https://github.com/jcchavezs/cmb2-conditionals) pluing but since it doesn't work properly on Group fields and not updated for 2 years, I decided to create a new one. The plugin currently supports checkboxes, radios and select lists.## Installation
- If you like, you can use WordPress ready verion [here](https://github.com/awran5/WP-CMB2-conditional-logic/) or simply include the `CMB2-conditional-logic.js` file in your project using [admin_enqueue_scripts](https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts)
- Adding conditional fields is just like before, just add a new `attributes` parameters: `data-conditional-id` which should match the conditional feild ID and `data-conditional-value` which should match the conditional value#### For adding conditional fields, add a new `attributes` parameter:
1. `data-conditional-id` which should match the conditional feild ID.
2. `data-conditional-value` which should match the conditional value.
3. `data-conditional-invert` use true to invert the behaviour```php
$cmb_demo->add_field( array(
'name' => __( 'Conditional select test:', 'your-text-domain' ),
'desc' => __('some description', 'your-text-domain'),
'id' => 'test_select_id',
'type' => 'select',
'options' => array(
'one' => __('one', 'your-text-domain' ),
'two' => __('two', 'your-text-domain'),
'three' => __('three', 'your-text-domain'),
),
) );
// conditional field
$cmb_demo->add_field(array(
'name' => __( 'Will show on value two selected', 'your-text-domain' ),
'desc' => __('some description', 'your-text-domain'),
'id' => 'test_select_depend',
'type' => 'select',
'options' => array(
'four' => __('Four', 'your-text-domain'),
'five' => __('Five', 'your-text-domain'),
'six' => __('Six', 'your-text-domain'),
),
'attributes' => array(
'data-conditional-id' => 'test_select_id',
'data-conditional-value' => 'two',
// 'data-conditional-invert' => true
),
) );
```
#### You can add more than 1 value to the `data-conditional-value` using ```php wp_json_encode( array( 'value 1', 'value 2' ) ) ``` like so:```php
'attributes' => array(
'data-conditional-id' => 'test_select_id',
'data-conditional-value' => wp_json_encode( array( 'two', 'three' ) ),
),
```#### If you like to use this plugin as a stand-alone plugin check my [conditionalScript](https://awran5.github.io/conditional-script/)