Support

Account

Home Forums Bug Reports Repeater with conditional – strange behavior

Solved

Repeater with conditional – strange behavior

  • I’m experiencing some odd behavior when adding rows with a repeater that have some conditional logic. essentially adding a row above your last row and save. ACF will copy the conditional field to the new row. Hard to explain but here are the steps to reproduce:

    1) fresh install wordpress
    2) fresh install of ACF
    3) install attached ACF field sets (repeater with a conditional)
    4) go to the sample page or any new page/post
    5) click “add row”
    6) click advanced
    7) in test field 1 type any value
    8) publish/update the page/post
    9) hover over the right column and click the + sign that pops up
    10) update the page/post
    11) click advanced on the row you just created and you’ll see that the test field has the same value as the first row instead of being blank as expected. If you repeat above but click advanced after creating the new row and click update the new field works as expected.

    or

    1) fresh install wordpress
    2) fresh install of ACF
    3) install attached ACF field sets (repeater with a conditional)
    4) go to the sample page or any new page/post
    5) click “add row”
    6) click advanced
    7) in test field 1 type any value
    8) publish/update the page/post
    9) click basic
    10) hover over the right column and click the + sign that pops up
    11) update the post/page
    12) click advanced on both rows
    13) the test field value is now on the first row instead of the second.

    Fieldsets

    if( function_exists('acf_add_local_field_group') ):
    
    acf_add_local_field_group(array (
    	'key' => 'group_58c7048b10b1c',
    	'title' => 'Conditional Test',
    	'fields' => array (
    		array (
    			'key' => 'field_58c70495e011a',
    			'label' => 'Repeater',
    			'name' => 'repeater',
    			'type' => 'repeater',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'collapsed' => '',
    			'min' => 0,
    			'max' => 0,
    			'layout' => 'row',
    			'button_label' => '',
    			'sub_fields' => array (
    				array (
    					'key' => 'field_58c704c2e011b',
    					'label' => 'Settings',
    					'name' => 'settings',
    					'type' => 'radio',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'wrapper' => array (
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'choices' => array (
    						'basic' => 'Basic',
    						'advanced' => 'Advanced',
    					),
    					'allow_null' => 0,
    					'other_choice' => 0,
    					'save_other_choice' => 0,
    					'default_value' => '',
    					'layout' => 'horizontal',
    					'return_format' => 'value',
    				),
    				array (
    					'key' => 'field_58c704f5e011c',
    					'label' => 'Test Field 1',
    					'name' => 'test_field_one',
    					'type' => 'text',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => array (
    						array (
    							array (
    								'field' => 'field_58c704c2e011b',
    								'operator' => '==',
    								'value' => 'advanced',
    							),
    						),
    					),
    					'wrapper' => array (
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'default_value' => '',
    					'placeholder' => '',
    					'prepend' => '',
    					'append' => '',
    					'maxlength' => '',
    				),
    			),
    		),
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'page',
    			),
    		),
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'post',
    			),
    		),
    	),
    	'menu_order' => 0,
    	'position' => 'normal',
    	'style' => 'default',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',
    	'active' => 1,
    	'description' => '',
    ));
    
    endif;
  • This is still marked as unread, did I submit this correctly?

  • Well, you have to remember that this forum is only really read by other users of ACF. Setting this up to test, will, takes a bit of work.

    Yes, I can confirm what your seeing, and I can tell you why.

    When you add the second field above the existing field, and the text field is hidden by conditional logic, this field is not submitted, and since it is not submitted, it is not updated. This field has the meta_key of repeater_0_test_field_one. The value is the second row used to be associated with this meta key. The value in the second row is now under the meta_key repeater_1_test_field_one and this is updated because it is not hidden. Again, the value in the first row in not updated or deleted, because it is not submitted.

    So, while it seems strange, it is expected behavior with the way conditional logic works.

    The reason that the fields are not submitted is, for example, say that you set that value as required. When ACF is validating a field it does not know that it was hidden by conditional logic and would return an error to the page that the field is required, even though it’s not due to conditional logic.

    Like I said, odd, but expected.

    If you want the developer to look at this you’ll need to submit a support ticket https://support.advancedcustomfields.com/new-ticket/. This link is shown at the top of the page when you start a new forum topic.

  • I’m sorry I thought this was were we were supposed to submit bugs and not just another forum.

    I understand what you are saying and I have been aware for some time that hidden conditional field don’t get submitted. I guess I’m just struggling to understand how I can submit an empty field, and after a page update the field is then populated with the field below it. If I submit an empty field (whether hidden or not) I would expect it to stay empty. I do understand what you are saying about the shifting IDs, I guess I just don’t agree that this is expected behavior.

    I made a vid here: http://productivemachine.com/acf.mp4 showing what I’m seeing. If this is what is supposed to happen I would like to make a formal request that it be handled differently because it’s breaking several of our sites. And the only solution I can see is to remove any conditional logic we have in our theme but this would cause a lot of clutter in the admin that I’d like to avoid if possible.

    Thanks!

  • It may not be 100% correct behavior, but given the way conditional logic works and how fields are stored and updated, this is the logical end result. Yes, it probably should be considered a but and should probably be reported to the developer.

    This forum, while there are topics for bug reports and feature requests, these things are really not handled here any more, the developer just does not have the time to keep up with this. I have spent over 30 hours this month replying to questions, that’s nearly a full week of time that would be taken away from Elliot’s work on ACF, and this does not count others doing the same kind of work.

    And I’m just a glorified user really. I’ve work with ACF and I’ve learned a lot, a good portion of it by investigating questions. In cases of bug reports I do my best to check them to see if they really are bugs. It’s good to report them here because other users might be able to give you help is solving them.

    In this case, I would probably say this should be reported to the developer, it is an unintended side effect of the way things work and he may be able to correct it, which is why I pointed you to the ticket system. There are other people there that will also check to see if it can be recreated and if forward the report on to Elliot so that he can take a look at it.

    It’s like a big filter to make sure the E is only spending time on things that really need his attention.

  • Thanks John, you have helped me in the past and I appreciate all the work you and Elliot do on ACF. Without ACF, wordpress would never really be a full featured CMS.

    I’ll submit the request to have a developer look at this. hopefully there might be a better way to handle.

    Thanks!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.