Forum Replies Created
-
AuthorPosts
-
NIU
ParticipantI had to implement the code in
conditional-logic.jsin order to have the functionality work well on fields which were already set before doing the update ingroup.jsNIU
ParticipantThe issue seems to be caused when updating the post with the sub-group collapsed. On load then it sets the sub-group as collapsed but still shows its subfields without taking into consideration the state of the sub-group
This is how it should be rendered when collapsed:

This is how it should be rendered when expanded:

NIU
ParticipantScreenshot below:

NIU
ParticipantYes when a group is collapsed all the subfields are hidden.
But when I integrated a conditional logic on the subfields, if that logic was being satisfied the subfields were being shown even when the group was collapsed.
NIU
ParticipantJust 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); }); } -
AuthorPosts