Viewing 2 reply threads
  • Author
    Posts
    • #7443
      andersonorui
      Participant

      Hi,

      I am having troubles with groups and conditions with nested groups with conditions.

      Ok, it sounds a little bit confusion…

      I have a select with three options and I need that different blocks of forms to be loaded depending on the select.

      The problem is that I have some conditions inside each block which is causing some issues because they don’t appear.

      Does anyone know what could be the problem?

      This is my code:

      <?php
      /*
      Title: Quiz Alternatives
      Post Type: oo_quiz
      */
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'quiz',
          'choices' => array(
              'poll' => 'Poll',
              'trivia' => 'Trivia',
              'personality' => 'Personality'
          )
      ));
      
      piklist('field', array(
          'type' => 'group',
          'field' => 'poll',
          'label' => 'Poll Quiz',
          'conditions' => array(
              array(
                  'field' => 'quiz',
                  'value' => 'poll'
              )
          ),
          'fields' => array(
              array(
                  'type' => 'text',
                  'field' => 'question',
                  'label' => 'Question'
              ),
              array(
                  'type' => 'group',
                  'field' => 'answers',
                  'label' => 'Answers',
                  'add_more' => true,
                  'fields' => array(
                      array(
                          'type' => 'select',
                          'field' => 'answer_format',
                          'choices' => array(
                              'text' => 'Text',
                              'file' => 'Image',
                              'url' => 'Video'
                          )
                      ),
                      array(
                          'type' => 'text',
                          'field' => 'answer_text',
                          'conditions' => array(
                              array(
                                  'field' => 'poll:answers:answer_format',
                                  'value' => 'text'
                              )
                          )
                      ),
                      array(
                          'type' => 'file',
                          'field' => 'answer_file',
                          'conditions' => array(
                              array(
                                  'field' => 'poll:answers:answer_format',
                                  'value' => 'file'
                              )
                          )
                      ),
                      array(
                          'type' => 'url',
                          'field' => 'answer_url',
                          'conditions' => array(
                              array(
                                  'field' => 'poll:answers:answer_format',
                                  'value' => 'url'
                              )
                          )
                      )
                  )
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'group',
          'field' => 'trivia',
          'label' => 'Trivia Quiz',
          'conditions' => array(
              array(
                  'field' => 'quiz',
                  'value' => 'trivia'
              )
          ),
          'fields' => array(
              array(
                  'type' => 'group',
                  'field' => 'questions',
                  'label' => 'Questions',
                  'add_more' => true,
                  'fields' => array(
                      array(
                          'type' => 'text',
                          'field' => 'question',
                          'label' => 'Question'
                      ),
                      array(
                          'type' => 'group',
                          'field' => 'answers',
                          'add_more' => true,
                          'fields' => array(
                              array(
                                  'type' => 'radio',
                                  'field' => 'personality_trivia_answer_correct',
                                  'choices' => array(
                                      'true' => 'Correct'
                                  )
                              ),
                              array(
                                  'type' => 'select',
                                  'field' => 'answer_format',
                                  'choices' => array(
                                      'text' => 'Text',
                                      'file' => 'Image',
                                      'url' => 'Video'
                                  )
                              ),
                              array(
                                  'type' => 'text',
                                  'field' => 'answer_text',
                                  'conditions' => array(
                                      array(
                                          'field' => 'trivia:questions:answers:answer_format',
                                          'value' => 'text'
                                      )
                                  )
                              ),
                              array(
                                  'type' => 'file',
                                  'field' => 'answer_file',
                                  'conditions' => array(
                                      array(
                                          'field' => 'trivia:questions:answers:answer_format',
                                          'value' => 'file'
                                      )
                                  )
                              ),
                              array(
                                  'type' => 'url',
                                  'field' => 'answer_url',
                                  'conditions' => array(
                                      array(
                                          'field' => 'trivia:questions:answers:answer_format',
                                          'value' => 'url'
                                      )
                                  )
                              )
                          )
                      )
                  )
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'group',
          'field' => 'personality',
          'label' => 'Personality Quiz',
          'conditions' => array(
              array(
                  'field' => 'quiz',
                  'value' => 'personality'
              )
          ),
          'fields' => array(
              array(
                  'type' => 'group',
                  'field' => 'questions',
                  'label' => 'Questions',
                  'add_more' => true,
                  'fields' => array(
                      array(
                          'type' => 'text',
                          'field' => 'question',
                          'label' => 'Question'
                      ),
                      array(
                          'type' => 'group',
                          'field' => 'answers',
                          'add_more' => true,
                          'fields' => array(
                              array(
                                  'type' => 'radio',
                                  'field' => 'personality_answer_correct',
                                  'choices' => array(
                                      'true' => 'Correct'
                                  )
                              ),
                              array(
                                  'type' => 'select',
                                  'field' => 'answer_format',
                                  'choices' => array(
                                      'text' => 'Text',
                                      'file' => 'Image',
                                      'url' => 'Video'
                                  )
                              ),
                              array(
                                  'type' => 'text',
                                  'field' => 'answer_text',
                                  'conditions' => array(
                                      array(
                                          'field' => 'personality:questions:answers:answer_format',
                                          'value' => 'text'
                                      )
                                  )
                              ),
                              array(
                                  'type' => 'file',
                                  'field' => 'answer_file',
                                  'conditions' => array(
                                      array(
                                          'field' => 'personality:questions:answers:answer_format',
                                          'value' => 'file'
                                      )
                                  )
                              ),
                              array(
                                  'type' => 'url',
                                  'field' => 'answer_url',
                                  'conditions' => array(
                                      array(
                                          'field' => 'personality:questions:answers:answer_format',
                                          'value' => 'url'
                                      )
                                  )
                              )
                          )
                      )
                  )
              )
          )
      ));
      
    • #7592
      tirins007
      Participant

      Had the same issue with nested add_mores, and unfortunately decided to switch to Carbon Fields because of it. I still think Piklist has future, it is just too buggy atm.

    • #7599
      Steve
      Keymaster

      @andersonorui– You don’t need to use an actual ‘field’ with a group. Try removing 'field' => 'poll' and 'field' => 'personality' and see if you can get that to work. Also groups within groups with conditions are not supported yet.

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