Viewing 2 reply threads
  • Author
    Posts
    • #2535

      Hi,

      I’ve created a metabox in a custom post type and I have a group field containing: one editor, and two textfields. This group represents comments in the custom post type and has add_more.
      The two textfields are disabled, because they are the comment’s author and date, And we don’t want them to be editable.
      When I add one more group I notice that the dafault values of the textfields (current user name and current date) are gone…
      Here’s the code:

      <?php
      /*
      Title: Comments
      Capability: manage_options
      Post Type: wt_support_ticket
      */
      global $current_user;
      get_currentuserinfo();
      
      piklist('field', array(
          'type' => 'group'
          ,'field' => 'comment_div'
          ,'label' => __('Comments') 
          ,'add_more' => true
          ,'fields' => array(
              array(
                'type' => 'text'
                ,'field' => 'comment_author'
                ,'label' => __("From")
                ,'value' => "$current_user->display_name"
                ,'attributes' => array(
                  "disabled" => true
                  ,"style" => "width:90%;"
                )
              )
              ,array(
                'type' => 'text'
                ,'field' => 'comment_time'
                ,'label' => __("At")
                ,'value' => date('l jS F Y')
                ,'attributes' => array(
                  "disabled" => true
                  ,"style" => "width:90%;"
                )
              )
              ,array(
                'type' => 'textarea'
                ,'field' => 'support_ticket_comment'
                ,'label' => __("Comment text")
                ,'template' => 'field'
                ,'value' => ''
                ,'attributes' => array(
                  'class' => 'comment'
                  ,'cols' => '80'
                  ,'rows' => '3'
                )
                ,'on_post_status' => array(
                  'value' => 'lock'
                )
              )
          )
        )
      );
      
      ?>

      What can I do?

      Thank you!

    • #2537
      Steve
      Keymaster

      @Angelos– Welcome to the Piklist Support Forums!

      Currently, default values for our Add-Mores only work on the initial field. We have it on our list to make it work on every add_more.

      Also, instead of using "style" => "width:90%;", you may want to try the Piklist grid system. Everything lays out beautifully, and it’s also responsive.

      Your code would look like this:

      piklist('field', array(
          'type' => 'group'
          ,'field' => 'comment_div'
          ,'label' => __('Comments') 
          ,'add_more' => true
          ,'fields' => array(
              array(
                'type' => 'text'
                ,'field' => 'comment_author'
                ,'label' => __("From")
                ,'value' => $current_user->display_name
                ,'columns' => 12
                ,'attributes' => array(
                  "disabled" => true
                )
              )
              ,array(
                'type' => 'text'
                ,'field' => 'comment_time'
                ,'label' => __("At")
                ,'value' => date('l jS F Y')
                ,'columns' => 12
                ,'attributes' => array(
                  "disabled" => true
                )
              )
              ,array(
                'type' => 'textarea'
                ,'field' => 'support_ticket_comment'
                ,'label' => __("Comment text")
                ,'template' => 'field'
                ,'columns' => 12
                ,'value' => ''
                ,'attributes' => array(
                  'class' => 'comment'
                  ,'cols' => '80'
                  ,'rows' => '3'
                )
                ,'on_post_status' => array(
                  'value' => 'lock'
                )
              )
          )
        )
      );
      

      One more thing, I noticed you have the on_post_status parameter set. I doubt you want that. We placed it in the Demos to show off the functionality. Here is a tutorial on using on_post_status, which explains how it works.

    • #2540

      Thanks @Steve!

Viewing 2 reply threads
  • The topic ‘Add_More and Default Values’ is closed to new replies.