Tagged: default_value, groups, metabox
- This topic has 2 replies, 2 voices, and was last updated 7 years, 4 months ago by
Angelos Mavroulakis.
-
AuthorPosts
-
-
October 7, 2014 at 3:15 pm #2535
Angelos MavroulakisMemberHi,
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!
-
October 7, 2014 at 3:57 pm #2537
SteveKeymaster@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_statusparameter 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. -
October 8, 2014 at 2:57 am #2540
Angelos MavroulakisMemberThanks @Steve!
-
-
AuthorPosts
- The topic ‘Add_More and Default Values’ is closed to new replies.