Viewing 1 reply thread
  • Author
    Posts
    • #8344
      riotxoa
      Participant

      Hi Piklist team,

      I’m implementing some conditions to show or hide fields when those conditions’ values changes. The conditions are implemented through radio buttons and simple select lists.

      Showing and hiding works fine, but i’m having troubles when i’m consulting a saved post with conditional values saved. If I change the value of a radio button, then the shown fields change correctly, but if I change back the radio button to its original status, then the value of the conditionally shown (and saved) field disappear (it appears blank).

      Here is my code. If I change de first radio status to ‘No’, and then go back to ‘Sí’ (Yes), the others fields’ values reset:

      piklist('field', array(
          'type' => 'radio',
          'field' => 'section01_hasbutton',
          'label' => '¿Botón de enlace?',
          'list' => false,
          'value' => 0, // set default value
          'choices' => array(
              0 => 'No',
              1 => 'Sí',
          )
      ));
      
      piklist('field', array(
          'type' => 'text',
          'field' => 'section01_button_text',
          'label' => 'Texto del botón de enlace',
          'conditions' => array(
              array(
                  'field' => 'section01_hasbutton',
                  'value' => 1
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'section01_buttonurltype',
          'label' => 'Tipo de enlace',
          'value' => 'url',
          'choices' => array(
              'url' => 'URL Externa',
              'post' => 'Entrada de Blog',
              'portfolio' => 'Portfolio',
              'page' => 'Página'
          ),
          'conditions' => array(
              array(
                  'field' => 'section01_hasbutton',
                  'value' => 1
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'url',
          'field' => 'section01_button_url_url',
          'label' => 'URL enlazada',
          'columns' => 12,
          'conditions' => array(
              array(
                  'field' => 'section01_hasbutton',
                  'value' => 1
              ),
              array(
                  'field' => 'section01_buttonurltype',
                  'value' => 'url'
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'section01_button_post_url',
          'label' => 'Entrada de Blog enlazada',
          'choices' => piklist(
              get_posts(
                  array(
                      'post_type' => 'post',
                      'numberposts' => -1,
                      'orderby' => 'post_date'
                  ),
                  'objects'
              ),
              array(
                  'ID'
                  ,'post_title'
              )
          ),
          'conditions' => array(
              array(
                  'field' => 'section01_hasbutton',
                  'value' => 1
              ),
              array(
                  'field' => 'section01_buttonurltype',
                  'value' => 'post'
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'section01_button_portfolio_url',
          'label' => 'Entrada de Portfolio enlazada',
          'choices' => piklist(
              get_posts(
                  array(
                      'post_type' => 'avada_portfolio',
                      'numberposts' => -1,
                      'orderby' => 'post_date'
                  ),
                  'objects'
              ),
              array(
                  'ID'
                  ,'post_title'
              )
          ),
          'conditions' => array(
              array(
                  'field' => 'section01_hasbutton',
                  'value' => 1
              ),
              array(
                  'field' => 'section01_buttonurltype',
                  'value' => 'portfolio'
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'select',
          'field' => 'section01_button_page_url',
          'label' => 'Página enlazada',
          'choices' => piklist(
              get_posts(
                  array(
                      'post_type' => 'page',
                      'numberposts' => -1,
                      'orderby' => 'post_date'
                  ),
                  'objects'
              ),
              array(
                  'ID'
                  ,'post_title'
              )
          ),
          'conditions' => array(
              array(
                  'field' => 'section01_hasbutton',
                  'value' => 1
              ),
              array(
                  'field' => 'section01_buttonurltype',
                  'value' => 'page'
              )
          )
      ));
      
    • #8349
      Steve
      Keymaster

      @riotxoa– Welcome to the Piklist community!

      This is currently the expected behavior on conditional fields. We have thought about adding a parameter to keep the value, but that is still on our backlog.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.