I’ve changed the code for the conditional logic script generation to use .on() instead of .live() and it seems to work for me now. The only issue I have is that validation is still performed on fields that have been hidden by conditional logic. I would prefer if a field is hidden by conditional logic that any validation for that field is ignored (i.e., is_required etc).
Here’s the code I’m using at the moment – although I’m hoping there’ll be a fix in the next update – this is around line 796 in acf.php
.
// conditional logic
// - isset is needed for the edit field group page where fields are created without many parameters
if (isset($field['conditional_logic']['status']) && $field['conditional_logic']['status']) {
$join = ' && ';
if ($field['conditional_logic']['allorany'] == "any") {
$join = ' || ';
}
$if = array();
foreach ($field['conditional_logic']['rules'] as $rule) {
$if[] = 'acf.conditional_logic.calculate({ field : "'. $field['key'] .'", toggle : "' . $rule['field'] . '", operator : "' . $rule['operator'] .'", value : "' . $rule['value'] . '"})' ;
}
//do script
echo '<script type="text/javascript">';
echo ' (function($) {';
echo ' var conditionalFN = function() {';
echo ' var field = $(".field-'.$field['key'].'");';
echo ' if('.implode($join, $if).') {';
echo ' field.show();';
echo ' } else {';
echo ' field.hide();';
echo ' }';
echo ' };';
foreach($field['conditional_logic']['rules'] as $rule ) {
echo ' $(".field-'.$rule['field'].' *[name]").on("change", function(){';
echo ' conditionalFN();';
echo ' });';
}
echo ' conditionalFN();';
echo ' })(jQuery);';
echo '</script>';
}