Skip to content

Commit

Permalink
Update bundled cmb2-conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg authored and moritzbappert committed Feb 6, 2019
1 parent 29249db commit 9cff0d1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions includes/libraries/cmb2-conditionals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
**License:** GPLv2 or later
**License URI:** [http://www.gnu.org/licenses/gpl-2.0.html](http://www.gnu.org/licenses/gpl-2.0.html)

## Disclaimer

This plugin is loved by many people but unfortunately I can not maintain it anymore so if you want to be a contributor just [ping me on gitter](https://gitter.im/jcchavezs).

## Description

**CMB2 Conditionals** is a plugin for [CMB2](https://github.com/WebDevStudios/CMB2) which allows developers to relate fields so one of them could only appear when one other have an specific value or when is not empty.
Expand Down
7 changes: 3 additions & 4 deletions includes/libraries/cmb2-conditionals/cmb2-conditionals.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ jQuery( document ).ready( function( $ ) {
$.each( ['show', 'hide'], function( i, ev ) {
var el = $.fn[ev];
$.fn[ev] = function() {
this.trigger( ev );
this.trigger( 'CMB2' + ev );
return el.apply( this, arguments );
};
});


/**
* Set up the functionality for CMB2 conditionals.
*/
Expand Down Expand Up @@ -143,14 +142,14 @@ jQuery( document ).ready( function( $ ) {
*/

// Remove the required property from form elements within rows being hidden.
conditionContext.on( 'hide', '.cmb-row', function() {
conditionContext.on( 'CMB2hide', '.cmb-row', function() {
$( this ).children( '[data-conditional-required="required"]' ).each( function( i, e ) {
$( e ).prop( 'required', false );
});
});

// Add the required property to form elements within rows being unhidden.
conditionContext.on( 'show', '.cmb-row', function() {
conditionContext.on( 'CMB2show', '.cmb-row', function() {
$( this ).children( '[data-conditional-required="required"]' ).each( function( i, e ) {
$( e ).prop( 'required', true );
});
Expand Down
9 changes: 7 additions & 2 deletions includes/libraries/cmb2-conditionals/cmb2-conditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

if ( ! class_exists( 'CMB2_Conditionals' ) ) {
if ( ! class_exists( 'CMB2_Conditionals', false ) ) {

/**
* CMB2_Conditionals Plugin.
Expand Down Expand Up @@ -261,7 +261,12 @@ protected function filter_field_data_to_save( $data_to_save, $field_id, $conditi
* Initialize the class.
*/
function cmb2_conditionals_init() {
$cmb2_conditionals = new CMB2_Conditionals();
static $cmb2_conditionals = null;
if ( null === $cmb2_conditionals ) {
$cmb2_conditionals = new CMB2_Conditionals();
}

return $cmb2_conditionals;
}
}
} /* End of class-exists wrapper. */
2 changes: 1 addition & 1 deletion includes/libraries/cmb2-conditionals/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"require": {
"php": ">5.2.4",
"webdevstudios/cmb2": "~v2.0"
"cmb2/cmb2": "~v2.0"
},
"suggest": {
"composer/installers": "~1.0"
Expand Down

0 comments on commit 9cff0d1

Please sign in to comment.