Multiple conditions do not apply

Support MB Conditional Logic Multiple conditions do not applyResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44291
    Aaron KesslerAaron Kessler
    Participant
    function is_event_post_type()
    {
      return get_post_type($_GET['post'] ?? null) === PREFIX . 'event';
    }
    
    $fields[] = [
      'title' => __('Kontakt', NAME_SPACE),
      'id' => PREFIX . 'event_contact_details',
      'post_types' => [PREFIX . 'event', 'page'],
      'include' => [
        'relation'        => 'OR',
        'template'  => ['template-desc.php'],
        'custom' => 'is_event_post_type'
      ],
      'context' => 'normal',
      'style' => 'default',
      'fields' => [
        [
          'id'        => PREFIX . 'inherit_event_contact_details_from_desc',
          'name'      => __('Kontakt überschreiben', NAME_SPACE),
          'type'      => 'switch',
          'style'     => 'rounded',
          'on_label'  => __('Ein', NAME_SPACE),
          'off_label' => __('Aus', NAME_SPACE),
          'label_description' => __('Überschreibt die Kontakdaten der Termin-Beschreibung', NAME_SPACE),
          'hidden'  => [
            ['page_template', 'template-desc.php']
          ]
        ],
        [
          'type' => 'custom_html',
          'std'  => '' . __('Kontakt-Details für Termine. Jeder Termin kann separat überschreiben werden.') . '
    ',
          'visible'  => [
            ['page_template', 'template-desc.php']
          ]
        ],
        [
          'type'       => 'heading',
          'name' => __('Link-Optionen', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('Text', NAME_SPACE),
          'id'   => PREFIX . 'event_link_text',
          'type' => 'text',
          'desc' => __('Empfohlen, Optional', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('URL', NAME_SPACE),
          'id'   => PREFIX . 'event_link_url',
          'type' => 'url',
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name'          => __('Parameter', NAME_SPACE),
          'id'            => PREFIX . 'event_link_url_params',
          'type'          => 'checkbox_list',
          'inline'        => true,
          'options' => [
            '_blank'   =>  __('URL in einem neuen Fenster/Tab öffnen', NAME_SPACE),
            'download'  =>  __('Download', NAME_SPACE),
          ],
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'type' => 'divider',
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('E-Mail-Adresse', NAME_SPACE),
          'id' => PREFIX . 'event_email',
          'type' => 'email',
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'type' => 'divider',
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('Telefonnummer', NAME_SPACE),
          'id' => PREFIX . 'event_phonenumber',
          'type' => 'text',
          'desc' => __('Die für den Menschen lesbare, formatierte Telefonnummer.', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('Telefon-Link', NAME_SPACE),
          'id' => PREFIX . 'event_phonenumber_raw',
          'type' => 'text',
          'desc' => __('Die unformatierte Telefonnummer, wie sie auch im Adressbuch eines Telefons verwendet wird.', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('Barrierefreie Telefonnummer', NAME_SPACE),
          'id' => PREFIX . 'event_phonenumber_a11ty',
          'type' => 'text',
          'desc' => __('Gesprochene Telefonnummer für Benutzer von Screenreadern.', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'type' => 'divider',
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('Fax-Nummer', NAME_SPACE),
          'id' => PREFIX . 'event_faxnumber',
          'type' => 'text',
          'desc' => __('Die lesbare, formatierte Faxnummer.', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
        [
          'name' => __('Barrierefreie Faxnummer', NAME_SPACE),
          'id' => PREFIX . 'event_faxnumber_a11ty',
          'type' => 'text',
          'desc' => __('Gesprochene Faxnummer für Benutzer von Screenreadern.', NAME_SPACE),
          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
          ]
        ],
      ],
    ];
    

    i would expect the fields like PREFIX . event_link_text to show up in pages wehre template-desc.php is applied and on the PREFIX . 'event' post type. when PREFIX . 'inherit_event_contact_details_from_desc' is toggled (true). But something must be wrong with

          'visible'  => [
            'relation'      => 'OR',
            'when' => [
              [PREFIX . 'inherit_event_contact_details_from_desc', true],
              ['page_template', 'template-desc.php']
            ]
    

    i can get only one of the conditonals to work. As far as i can tell i did nothing wrong. Please fix this bug or prove me wrong.

    #44299
    PeterPeter
    Moderator

    Hello,

    i can get only one of the conditionals to work, it is obvious based on your condition.

    The field inherit_event_contact_details_from_desc is hidden when page_template is template-desc.php:

        [
          'id'        => PREFIX . 'inherit_event_contact_details_from_desc',
          'name'      => __('Kontakt überschreiben', NAME_SPACE),
          'type'      => 'switch',
          'style'     => 'rounded',
          'on_label'  => __('Ein', NAME_SPACE),
          'off_label' => __('Aus', NAME_SPACE),
          'label_description' => __('Überschreibt die Kontakdaten der Termin-Beschreibung', NAME_SPACE),
          'hidden'  => [
            ['page_template', 'template-desc.php']
          ]
        ]
    

    If you set the condition of the field event_link_text displayed when the field inherit_event_contact_details_from_desc is true and page_template is template-desc.php, one condition will not work.
    Because if page_template is template-desc.php, the field inherit_event_contact_details_from_desc is hidden and you cannot switch on/off the field.

    Also, please notice that the nested conditional logic is not working correctly. That means if the field event_link_text is shown/hidden based on the field inherit_event_contact_details_from_desc value and the field inherit_event_contact_details_from_desc is shown/hidden based on another condition, the condition of the field event_link_text will not work correctly. Refer to this topic https://support.metabox.io/topic/or-logic-not-working/

    #44303
    Aaron KesslerAaron Kessler
    Participant

    Thanks. I defined separate meta boxes for the custom post type and the page template for now. If https://support.metabox.io/topic/or-logic-not-working/ is still not supported after 3,5 years, should it not be mentioned in https://docs.metabox.io/extensions/meta-box-conditional-logic/ ?

    #44308
    PeterPeter
    Moderator

    Hello,

    Regarding the nested condition, the development team is still working on this issue and it looks more complicated. Hopefully, it will be fixed soon.

    Thank you.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.