Created
November 11, 2016 09:47
-
-
Save maheshwaghmare/f4f32bbeb2c79d4767fb30f54c83a8a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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']) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
god bless you!