The default parameter don’t work in group fields
-
When i use this code:
$pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'place', 'id' => 'place', 'type' => 'select', 'show_option_none' => true, 'options' => $places_options, ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'kidum_state', 'id' => 'state', 'type' => 'select', 'show_option_none' => true, 'default' => 'active', 'options' => array( 'active' => 'active', 'canceled' => 'canceled', ), ) );I get ‘canceled’ as default option.
-
not sure I’m managing to recreate at all, however, let’s outline some steps.
You create and fill out a grouping. Hit save.
After that, you create a new grouping, and remove the first one?
Once you remove the first one, the 2nd one you had created inherited the values from the first one?Alternative:
You create and fill out a grouping. Hit save.
After that, you decide you don’t want that initial one, and remove it.
All groups you create afterwards inherit the values from the first one?I reset the field (let’s start clean) by doing:
update_post_meta( '882', 'pro_paypal_kidum', '' );and then hit “update” on the edit post page.Then i add values to the first (only) group. hit “update”.
Now when i add another group (no matter how many of them) they all have the same values of the first one. btw – only the text fields. the select fields are blank (like suppose to be).
-
This reply was modified 9 years, 1 month ago by
Begin.
Really hard for me to say with that detail regarding the text fields. Your configuration code is set to have them all be read-only, and I don’t have any way of knowing what may have been done in the past to provide values for them.
only added values by using:
$my_group = get_post_meta( $propostid, 'pro_paypal_kidum', true ); $my_group[] = array( 'place' => $stickyplaceid, 'state' => 'active', 'payer_mail' => $payer_email, 'start' => $format_action_date->format('d/m/Y'), 'subscr_id' => $subscr_id, 'price' => $mc_amount3, 'fee' => $mc_fee); update_post_meta( $propostid, 'pro_paypal_kidum', $my_group );Also tried removing all the readonly attributes and edit the field values manually in the edit post page. still will add the next one with the values of the last one.
-
This reply was modified 9 years, 1 month ago by
Begin.
Another point: when i have only one group field and i hit “remove group” it won’t clear the values (it’s suppose to in the last version right?)
Another very interesting point now i see: (following the last comment) it will clear the select fields!
Also tried to change the group field’s id so it will clear anything associated with that field. still same problem.
Here is a screencast gif of the problem.
One thing I do want to remind of and keep in mind is that this is very much a new feature that was just added in the past 24 hours. Is possible that some details slipped by.
@jtsternberg I was able to finally recreate this, and it feels like https://github.com/CMB2/CMB2/issues/853 started occurring for text fields now.
Steps that recreated for me:
* Add a new post
* Add some meta to a group, specifically text fields
* Save the post
* Add a new group
* Note that text fields are pre-populated.CMB2 config that worked for me for this, don’t forget to change the post type to somethin you have registered:
add_action( 'cmb2_init', 'add_pro_paypal_box' ); function add_pro_paypal_box() { global $listmesettings_id; $pro_paypal_box = new_cmb2_box( array( 'id' => '_pro_paypal_box', 'title' => 'מצבי קידום ותשלומים', 'object_types' => array( 'movie' ), 'context' => 'normal', 'priority' => 'high', ) ); // Kidum group $pro_paypal_kidum = $pro_paypal_box->add_field( array( 'id' => 'pro_paypal_kidum', 'type' => 'group', 'options' => array( 'group_title' => 'group {#}', ), ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'מקום', 'id' => 'place', 'type' => 'select', 'show_option_none' => true, 'options' => array( 1 => 'something' ), ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'מצב קידום', 'id' => 'state', 'type' => 'select', 'show_option_none' => true, 'options' => array( 'active' => 'פעיל', 'canceled' => 'מבוטל', ), ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'מייל של חשבון משלם', 'id' => 'payer_mail', 'type' => 'text', ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'התחלה', 'id' => 'start', 'type' => 'text_small', ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'סיום', 'id' => 'end', 'type' => 'text_small', ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'מזהה תשלום חוזר', 'id' => 'subscr_id', 'type' => 'text_small', ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'סכום', 'id' => 'price', 'type' => 'text_small', ) ); $pro_paypal_box->add_group_field( $pro_paypal_kidum, array( 'name' => 'עמלה', 'id' => 'fee', 'type' => 'text_small', ) ); }thanks! can you explain what exactly in the code that you posted is fixing the problem?
Doesn’t seem to fix it for me.
The code I posted doesn’t have a fix, it’s just a modified version of what you posted earlier to make it render on my end. I was posting it for Justin to use for any testing he wants to try.
If you want to @bentalgad, you can read over issue 853 that I linked above.
Oh, ok, it sounded like that, but i wasn’t sure 🙂
Let me know if you need me to test something else to figure this out…
Thanks!
Michael is saying “it works” in that he is able to replicate your issue. And so was I.
I narrowed the issue down to being specific to groups which do not have the
'sortable'option set totrue: https://github.com/CMB2/CMB2/blob/trunk/example-functions.php#L489As a temporary workaround, you can add the ‘sortable’ param and it will work. I will push up a hotfix shortly.
-
This reply was modified 9 years, 1 month ago by
The topic ‘The default parameter don’t work in group fields’ is closed to new replies.