Viewing 0 reply threads
  • Author
    Posts
    • #8049
      robertfyffe
      Participant

      I am trying to use conditions within a 1 level deep group but I am having some problems.

      I am trying to set a condition based on if the user has chosen primary from the mew_location select list. If they haven’t it should hide the field mew_item_children. When I add the condition to this field it completely prevents the group from displaying.

      My Code:

      
      <?php
      piklist('field', array(
        'type' => 'radio', 
        'field' => 'mew_type',
        'label' => __('What type of menu would you like to build?', WPDMEW_TEXT_DOMAIN),
        'value' => '',
        'column' => 12,
        'choices' => array(
          'standard' => __('Standard Menu', WPDMEW_TEXT_DOMAIN),
          'mega' => __('Mega Menu', WPDMEW_TEXT_DOMAIN),
        )
      ));
      
      piklist('field', array(
        'type' => 'select',
        'field' => 'mew_location',
        'label' => __('Where will this appear?', WPDMEW_TEXT_DOMAIN),
        'value' => '',
        'column' => 12,
        'choices' => array(
          '' => '',
          'primary' => __('Primary Menu', WPDMEW_TEXT_DOMAIN),
          'secondary' => __('Secondary Menu', WPDMEW_TEXT_DOMAIN),
          'social' => __('Social Menu', WPDMEW_TEXT_DOMAIN),
          'footer' => __('Footer Menu', WPDMEW_TEXT_DOMAIN),
        ),
        'conditions' => array(
          array(
            'relation' => 'or',
            'field' => 'mew_type',
            'value' => array(
              'standard',
              'mega'
            ),
          )
        )
      ));
      
      piklist('field', array(
        'type' => 'group',
        'field' => 'mew_primary_menu',
        'label' => __('', WPDMEW_TEXT_DOMAIN),
        'description' => __('', WPDMEW_TEXT_DOMAIN),
        'add_more' => true,
        'columns' => 12,
        'fields' => array(
          array(
            'type' => 'select', 
            'field' => 'mew_item_type',
            'label' => __('What kind of nav item do you want to add?', WPDMEW_TEXT_DOMAIN),
            'value' => '',
            'column' => 6,
            'choices' => array(
              '' => '',
              'page' => __('Page', WPDMEW_TEXT_DOMAIN),
              'post' => __('Post', WPDMEW_TEXT_DOMAIN),
              'external' => __('External', WPDMEW_TEXT_DOMAIN),
            ),
            'conditions' => array(
              array(
                'relation' => 'or',
                'field' => 'mew_location',
                'value' => array(
                  'primary',
                  'secondary',
                  'social',
                  'footer',
                )
              ),
            ),
          ),
          array(
            'type' => 'select', 
            'field' => 'mew_item_post',
            'label' => __('Select an existing post', WPDMEW_TEXT_DOMAIN),
            'value' => '',
            'column' => 6,
            'choices' => wpdmw_get_posts(),
            'conditions' => array(
              array(
                'field' => 'mew_primary_menu:mew_item_type',
                'value' => 'post',
              ),
            ),
          ),
          array(
            'type' => 'select', 
            'field' => 'mew_item_page',
            'label' => __('Select an existing page', WPDMEW_TEXT_DOMAIN),
            'column' => 6,
            'choices' => wpdmw_get_pages(),
            'conditions' => array(
              array(
                'field' => 'mew_primary_menu:mew_item_type',
                'value' => 'page',
              ),
            ),
          ),
          array(
            'type' => 'text',
            'field' => 'mew_item_external',
            'columns' => 12,
            'label' => __('Enter an external URL', WPDMEW_TEXT_DOMAIN),
            'validate' => array(
              array(
                'type' => 'url'
              )
            ),
            'conditions' => array(
              array(
                'field' => 'mew_primary_menu:mew_item_type',
                'value' => 'external',
              ),
            ),
          ),
          array(
            'type' => 'select', 
            'field' => 'mew_item_children',
            'label' => __('Display children of this page if exists?', WPDMEW_TEXT_DOMAIN),
            'value' => '',
            'column' => 12,
            'choices' => array(
              '' => '',
              '1' => __('Yes', WPDMEW_TEXT_DOMAIN),
              '0' => __('No', WPDMEW_TEXT_DOMAIN),
            ),
            'conditions' => array(
              'relation' => 'and',
              array(
                'field' => 'mew_primary_menu:mew_item_type',
                'value' => 'page',
              ),
              array(
                'field' => 'mew_primary_menu:mew_item_page',
                'value' => array(
                  ''
                ),
                'compare' => '!='
              ),
              array(
                'field' => 'mew_location',
                'value' => 'primary',
                'compare' => '='
              ),
            ),
          ),
          array(
            'type' => 'select', 
            'field' => 'mew_bg_display',
            'label' => __('Add a background image?', WPDMEW_TEXT_DOMAIN),
            'value' => '',
            'column' => 12,
            'choices' => array(
              '' => '',
              'yes' => __('Yes', WPDMEW_TEXT_DOMAIN),
              'no' => __('No', WPDMEW_TEXT_DOMAIN),
            ),
            'conditions' => array(
              array(
                'field' => 'mew_primary_menu:mew_item_children',
                'value' => array(
                  ''
                ),
                'compare' => '!='
              ),
            ),
          ),
          array(
            'type' => 'file',
            'field' => 'mew_item_bg_lg',
            'columns' => 6,
            'scope' => 'post_meta',
            'label' => __('Large', WPDMEW_TEXT_DOMAIN),
            'options' => array(
              'modal_title' => __('Add Image', WPDMEW_TEXT_DOMAIN),
              'button' => __('Add', WPDMEW_TEXT_DOMAIN),
            ),
            'conditions' => array(
              array(
                'field' => 'mew_primary_menu:mew_bg_display',
                'value' => 'yes',
              ),
            ),
            'validate' => array(
              array(
                'type' => 'limit',
                'options' => array(
                  'min' => 1,
                  'max' => 1
                )
              )
            )
          ),
          array(
            'type' => 'file',
            'field' => 'mew_item_bg_sm',
            'columns' => 6,
            'scope' => 'post_meta',
            'label' => __('Small', WPDMEW_TEXT_DOMAIN),
            'options' => array(
              'modal_title' => __('Add Image', WPDMEW_TEXT_DOMAIN),
              'button' => __('Add', WPDMEW_TEXT_DOMAIN),
            ),
            'conditions' => array(
              array(
                'field' => 'mew_primary_menu:mew_bg_display',
                'value' => 'yes',
              ),
            ),
            'validate' => array(
              array(
                'type' => 'limit',
                'options' => array(
                  'min' => 1,
                  'max' => 1
                )
              )
            )
          ),
        ),
      ));
      

      I am finding the conditions in general very buggy. Is there something wrong with my code?

Viewing 0 reply threads
  • You must be logged in to reply to this topic.