Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Helper showControlIfhasValues()
*/
function showControlIfhasValues( setting, ExpectedValues ) {
return function( control ) {
// Check the current value in the array of ExpectedValues
var isDisplayed = function() {
return $.inArray( setting.get(), ExpectedValues ) !== -1;
};
var setActiveState = function() {
control.active.set( isDisplayed() );
};
control.active.validate = isDisplayed;
setActiveState();
setting.bind( setActiveState );
};
}
/**
* Test Control Dependency
*/
wp.customize( 'select-control-1', function( setting ) {
// Show control 'text-control-1' if control 'select-control-1' value has 'one' or 'two'
wp.customize.control( 'text-control-1', showControlIfhasValues( setting, ['one','two']) );
// Show control 'text-control-2' if control 'select-control-1' value has 'one'.
wp.customize.control( 'text-control-2', showControlIfhasValues( setting, ['one']) );
// Show control 'text-control-2' if control 'select-control-1' value has 'one'.
wp.customize.control( 'text-control-4', showControlIfhasValues( setting, ['one']) );
// Show control 'text-control-2' if control 'select-control-1' value has 'one' or 'three'.
wp.customize.control( 'text-control-3', showControlIfhasValues( setting, ['one', 'three']) );
} );
@kmob2

This comment has been minimized.

Copy link

@kmob2 kmob2 commented Dec 6, 2016

This is great. I appreciate it. Thank you!

@uNkset

This comment has been minimized.

Copy link

@uNkset uNkset commented Oct 10, 2018

god bless you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment