AdvancedCustomFields / AdvancedCustomFields/acf
ACF 5.8-Beta-4.1: Conditionally hidden sub field should return empty value instead of default
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
The case:
Two subfields:
- Arrangement: blocks (default), slides
- Position: before (default), after
A position choice is shown only if "slides" is chosen in the first control (conditional logic).
The issue:
Steps:
- When I insert a block and don't touch anything, the returned position value is empty. This is valid and expected.
- But when I click "Slides", even once, go back to "Blocks" and save the page, from that moment the returned position will never be empty. It returns default value "before" instead. I expect that conditionally hidden field will still return empty value.
The code:
/**
* Test ACF blocks in 5.8-beta4
*/
function my_acf_block_render_callback() {
$settings = get_field( 'my-settings' );
echo 'Position: ' . ( ! empty( $settings['position'] ) ? $settings['position'] : 'empty' );
}
add_action( 'acf/init', 'my_acf_blocks_init' );
function my_acf_blocks_init() {
/**
* Register block
*/
acf_register_block_type( array(
'name' => 'my',
'title' => __( 'My Test Block', 'my-acf' ),
'description' => __( 'A block for entering a link name and a custom URL.', 'my-acf' ),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'formatting',
'icon' => 'external',
'keywords' => array(),
'supports' => array( 'align' => false ),
'mode' => 'edit',
) );
/**
* Define block fields
*/
acf_add_local_field_group( array(
'key' => "group_my",
'title' => __( 'Block :: My Test Block', 'my-acf' ),
'location' => array(
array(
array(
'param' => 'block',
'operator' => '==',
'value' => 'acf/my',
),
),
),
'fields' => array(
array(
'key' => "field_my-settings",
'label' => false,
'name' => "my-settings",
'type' => 'group',
'layout' => 'block',
'sub_fields' => array(
/* Arrangement */
array(
'key' => "field_my-settings-arrangement",
'label' => __( 'Arrangement', 'my-acf' ),
'name' => 'arrangement',
'type' => 'button_group',
'choices' => array(
'blocks' => __( 'Blocks', 'my-acf' ),
'slides' => __( 'Slides', 'my-acf' ),
),
'default_value' => 'blocks',
'layout' => 'horizontal',
'wrapper' => array(
'width' => '50',
),
),
/* Position */
array(
'key' => "field_my-settings-position",
'label' => __( 'Images position', 'my-acf' ),
'name' => 'position',
'type' => 'radio',
'choices' => array(
'before' => __( 'Before', 'my-acf' ),
'after' => __( 'After', 'my-acf' ),
),
'default_value' => 'before',
'layout' => 'horizontal',
'wrapper' => array(
'width' => '50',
),
'conditional_logic' => array(
array(
array(
'field' => "field_my-settings-arrangement",
'operator' => '==',
'value' => 'slides',
),
),
),
),
),
), // EOF settings
),
) );
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PHP reproduction in the issue and repeat the save sequence: leave Blocks selected, switch to Slides, return to Blocks, and save. Trace how the ACF group returns the conditionally hidden position subfield after saving. Done means the position value remains empty when the field is hidden, rather than returning its default value "before".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100