Forum Replies Created
-
AuthorPosts
-
September 5, 2018 at 12:56 AM in reply to: โ Disable (delete) fields that are hidden conditionally? #11245
mgratch
Participant@calebcook I think this is based on something I got in the forum, but it looks through group field values being saved and removes empty values that are not visible upon submission.
mgratch
ParticipantI get your point, I can't think of a situation where ALL clones would have to meet 1 condition, but regardless I get it.
in case anyone needs it or you see a good way to include it I created the following callback:
// js functions function checkCompareStatement(needle, haystack, compare) { if (needle === null || typeof needle === 'undefined') { needle = ''; } switch (compare) { case '=': if ($.isArray(needle) && $.isArray(haystack)) { return $(needle).not(haystack).length === 0 && $(haystack).not(needle).length === 0; } return needle == haystack; case '>=': return needle >= haystack; case '>': return needle > haystack; case '<=': return needle <= haystack; case '<': return needle < haystack; case 'contains': if ($.isArray(needle)) { return $.inArray(haystack, needle) > -1; } else if ($.type(needle) === 'string') { return needle.indexOf(haystack) > -1; } return false; case 'in': if (!$.isArray(needle)) { return haystack.indexOf(needle) > -1; } var found = false; $.each(needle, function(index, value) { if ($.isNumeric(value)) { value = parseInt(value); } if (haystack.indexOf(value) > -1) { found = true; } }); return found; case 'start_with': case 'starts with': return needle.indexOf(haystack) === 0; case 'end_with': case 'ends with': haystack = new RegExp(haystack + '$'); return haystack.test(needle); case 'match': haystack = new RegExp(haystack); return haystack.test(needle); case 'between': if ($.isArray(haystack) && typeof haystack[0] !== 'undefined' && typeof haystack[1] !== 'undefined') { return checkCompareStatement(needle, haystack[0], '>=') && checkCompareStatement(needle, haystack[1], '<='); } } } function check_for_clone(haystack, compare, needle) { var val; var $elements = $('[name*="' + haystack + '"]'); $.each($elements, function() { if (true === checkCompareStatement(needle, this.value, compare)) { val = this.value; return false; } }) return val; } // your field or metabox 'visible' => array( 'when' => array( array( 'check_for_clone("sf_sign_module_type", "=", "room-availability-module")', '=', 'room-availability-module') , array( 'check_for_clone("sf_sign_module_type", "=", "room-current-activity-module")', '=', 'room-current-activity-module'), array( 'check_for_clone("sf_sign_module_type", "=", "room-upcoming-activity-module")', '=', 'room-upcoming-activity-module'), ), 'relation' => 'or', ),I am simply re-using the built-in
checkCompareStatement-- if some of your functions had global access it could be very useful, along with other conditional passed parameters, i.e.needle,compare,haystackmgratch
ParticipantHi,
Thank you for such a quick a reply.
When I select the value
room-availability-modulefrom thesf_sign_module_typeselect field theroom-availabilitymetabox is visible. Unfortunatelysf_sign_module_typeclones i.e.sf_sign_modules[1][sf_sign_module_type]still do not trigger the conditional action.Thanks again!
-
AuthorPosts