Support Forum
Support › Meta Box Conditional Logic › Conditional Logic and Group extensions › Reply To: Conditional Logic and Group extensions
Just a small update. We managed to work around it but we made some changes to both extensions (conditional logic and group). I know this is not ideal and on the next update we will be loosing all changes. Therefore I am attaching the code here such that the plugin author can include these changes in the next update:
meta-box-group/group.js : line 37
group.toggle.updateState = function( $group, state ) {
var $input = $group.find( '.rwmb-group-state' ).last().find( 'input' );
if ( state ) {
$input.val( state );
} else {
state = $input.val();
}
// Store current state. Will be preserved when cloning.
$input.attr( 'data-current', state );
$input.trigger('change'); //<<--added this line so that conditional-logic will run the logic when _state changes
$group.toggleClass( 'rwmb-group-collapsed', 'collapsed' === state )
.find( '.rwmb-group-toggle-handle' ).first().attr( 'aria-expanded', 'collapsed' !== state );
};
meta-box-conditional-logic/js/conditional-logic.js : line 381
function guessSelector(fieldName, selectorCache) {
if (compare(fieldName, '(', 'contains')) {
return '';
}
if (!selectorCache) {
selectorCache = globalSelectorCache;
}
if (isUserDefinedSelector(fieldName)) {
return fieldName;
}
//Added below line to check if scope is cloneable or not
var cloneable = $(selectorCache.$scope).hasClass('rwmb-clone');
var selectors = [
fieldName,
'#' + fieldName,
'[name="' + fieldName + '"]',
'[name^="' + fieldName + '"]',
'[name*="' + fieldName + '"]'
];
//Added below condition to prepend the exact name attribute to the selectors array
if (cloneable) {
$.each(selectors, function (index, pattern) {
var tempSelector = selectorCache.get(pattern);
if (tempSelector.length > 0) {
selectors.unshift('[name="' + tempSelector.attr('name') + '"]');
}
});
}
var selector = _.find(selectors, function (pattern) {
return selectorCache.get(pattern).length > 0;
});
return selector ? selector : '';
}
meta-box-conditional-logic/js/conditional-logic.js : line 529
// Listening eventSource apply conditional logic when eventSource is change.
if (watchedElements.length > 1) {
//Added the following loop, to run the coniditional logic on initialization
$.each(watchedElements.split(','), function(){
var $scope = getFieldScope($(this));
runConditionalLogic($scope);
});
$document.on('change keyup', watchedElements, function () {
var $scope = getFieldScope($(this));
runConditionalLogic($scope);
});
}