Support

Account

Home Forums Bug Reports ACF Form Conditional Display

Solving

ACF Form Conditional Display

  • I noticed something a bit odd with a form I created using acf_form.

    I have select fields that display other selects when a user is submitting the form. Example image below of the user submission form.

    User selecting conditional items.

    When the user saves the form it saves it as a draft post. When I load up the draft for review, the Category field is filled in with “Events” because that is what the user chose.

    However the Tag field does not display even though it shows events as selected. Image below of the draft post being edited through the WordPress Admin by an admin.

    Conditional not loading

    If in the Wp-admin of the post draft I add another Category tag or remove events and re-add it the correct conditional shows up with the correct data in place.

    added addtional item and other conditional now displays.

    So the front end form I’m creating for users to submit to works as intended. Its just the WP Admin side when loading up the draft post for review.

    The Event conditional should be met on load but isn’t even though the data seems to be there. Is this something on my end or a bug?

    The select fields I’m using to do this is just a basic select field with the stylized UI and AJAX lazy load.

    I’m using ACF Pro 5.3.0 and WP 4.3

  • This seems to be related to this, at least it seems similar. The other bug was just the back end and this one seems to involve the front end as well. Though I could be wrong.

    http://support.advancedcustomfields.com/forums/topic/filter-by-taxonomy-disappears/

    Will see what I can do about getting the developer’s attention.

  • For anyone suffering from this, I have a workaround that helps my particular case until the bug is fixed. This basically triggers a javascript “change” event on the Select2 component, which snaps the conditional logic into shape. This will only work for when there is at least one item in the select.

    
    function acf_fix_select2( $field ) {
      if (
        !$field['ui'] ||                          // field isn't select2
        strpos( $field['id'], 'acfcloneindex' )   // field is hidden <select>
      ) {
        return;
      }
    
      ?>
        <script type="text/javascript">
          jQuery(function(){
            jQuery('#s2id_<?php echo $field['id']; ?> .select2-choices input:first')
              .trigger('change');
            acf.unload.off();
          });
        </script>
      <?php
    }
    add_action( 'acf/render_field/type=select', 'acf_fix_select2', 10, 1 );
    
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘ACF Form Conditional Display’ is closed to new replies.