diff --git a/conditional_fields.module b/conditional_fields.module index d050e0b..ca19fbf 100644 --- a/conditional_fields.module +++ b/conditional_fields.module @@ -560,36 +560,38 @@ function conditional_fields_form_after_build($form, &$form_state) { _conditional_fields_element_add_property($dependent_form_field, '#element_validate', 'conditional_fields_dependent_validate', 'append'); } - // Add the $state into the correct logic group in $states. - foreach ($state as $key => $constraints) { - foreach ($constraints as $selector => $constraint) { - // Add the constraint in an array to avoid overwriting other - // dependencies' states with the same selector. - $states[$key][$options['grouping']][$selector][] = $constraint; - } + if (isset($state)) { + // Add the $state into the correct logic group in $states. + foreach ($state as $key => $constraints) { + foreach ($constraints as $selector => $constraint) { + // Add the constraint in an array to avoid overwriting other + // dependencies' states with the same selector. + $states[$key][$options['grouping']][$selector][] = $constraint; + } - // Build effect settings for effects with options. - // TODO: add dependee key to allow different effects on the same selector. - if ($options['effect'] && $options['effect'] != 'show') { - $selector = conditional_fields_field_selector(drupal_array_get_nested_value($form, array($dependent_location[0]))); - // Convert numeric strings to numbers. - foreach ($options['effect_options'] as &$effect_option) { - if (is_numeric($effect_option)) { - $effect_option += 0; + // Build effect settings for effects with options. + // TODO: add dependee key to allow different effects on the same selector. + if ($options['effect'] && $options['effect'] != 'show') { + $selector = conditional_fields_field_selector(drupal_array_get_nested_value($form, array($dependent_location[0]))); + // Convert numeric strings to numbers. + foreach ($options['effect_options'] as &$effect_option) { + if (is_numeric($effect_option)) { + $effect_option += 0; + } } + $effects[$selector] = array( + 'effect' => $options['effect'], + 'options' => $options['effect_options'], + ); } - $effects[$selector] = array( - 'effect' => $options['effect'], - 'options' => $options['effect_options'], - ); - } - // Apply reset dependent to default if untriggered behavior. - if (in_array(CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED, $behaviors)) { - // Add property to element so conditional_fields_dependent_validate() can - // pick it up. - $dependent_form_field['#conditional_fields_reset_if_untriggered'] = TRUE; - unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED]); + // Apply reset dependent to default if untriggered behavior. + if (in_array(CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED, $behaviors)) { + // Add property to element so conditional_fields_dependent_validate() can + // pick it up. + $dependent_form_field['#conditional_fields_reset_if_untriggered'] = TRUE; + unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED]); + } } }