Skip to content

Field dependencies not working after page refresh in repeater fields #4072

@blackandcode

Description

@blackandcode

Steps to reproduce

  1. Create a Redux configuration with a repeater field containing switch fields with required dependencies
  2. Add the following field structure inside a repeater:
    array(
        'type' => 'repeater',
        'fields' => array(
            array(
                'id' => 'show_link',
                'type' => 'switch',
                'title' => 'Show Link',
                'default' => '0',
            ),
            array(
                'id' => 'absolute_or_relative_url',
                'type' => 'switch',
                'title' => 'Absolute URL',
                'default' => '0',
                'required' => array('show_link', '=', '1'),
                'force_output' => true,
            ),
            array(
                'id' => 'link_to_page',
                'type' => 'select',
                'data' => 'pages',
                'required' => array(
                    array('show_link', '=', '1'),
                    array('absolute_or_relative_url', '=', '1'),
                ),
                'force_output' => true,
            ),
            array(
                'id' => 'link_to_absolute_url',
                'type' => 'text',
                'required' => array(
                    array('show_link', '=', '1'),
                    array('absolute_or_relative_url', '=', '0'),
                ),
                'force_output' => true,
            ),
        ),
    )
  3. Save the Redux configuration and navigate to the admin page
  4. Enable the first switch (show_link) - dependent fields appear correctly
  5. Configure the dependent fields and save
  6. Refresh the page or navigate away and return

Expected Behavior

  • After page refresh, dependent fields should remain visible when their parent conditions are met
  • Field visibility should be restored based on saved values
  • The same behavior should work consistently both inside and outside repeater fields

Actual Behavior

  • Outside repeater: Fields work correctly - dependent fields remain visible after page refresh when conditions are met
  • Inside repeater: Dependent fields become hidden after page refresh, even when their parent conditions are satisfied and values are saved correctly
  • Field dependencies work on first interaction but fail to restore visibility state after page reload

Any Error Details (PHP/JavaScript)

No PHP errors are generated. JavaScript console shows no errors in dev mode.

Additional Context

Working Configuration (Outside Repeater)

The identical field configuration works perfectly when placed outside of a repeater field. Fields remain visible after page refresh when their conditions are met.

Attempted Solutions

Tried multiple approaches that should work according to Redux documentation:

  • Using force_output => true on dependent fields
  • String values ('1', '0') instead of integers for comparisons
  • Nested required arrays: array(array('field1', '=', '1'), array('field2', '=', '0'))
  • Single-level required arrays: array('field1', '=', '1')
  • Various comparison operators (=, equals, !=)

Environment

  • Redux Framework latest
  • WordPress latest version
  • PHP 8.3+
  • Modern browsers (Chrome, Firefox, Safari) - issue occurs in all

Impact

This appears to be a fundamental issue with how Redux handles field dependencies within repeater contexts after page initialization. The field dependency JavaScript logic seems to not properly restore field visibility states for repeater field children when the page loads with existing saved values.

Suggested Investigation Areas

  1. Redux JavaScript initialization sequence for repeater fields
  2. Field dependency state restoration logic in repeater contexts
  3. DOM event binding for dependent fields within dynamically generated repeater items
  4. Potential timing issues between repeater field rendering and dependency evaluation

This bug significantly impacts the usability of complex repeater configurations that rely on conditional field visibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions