std value in nested group doesn't work

Support MB Group std value in nested group doesn't work

  • This topic has 1 reply, 2 voices, and was last updated 1 week ago by PeterPeter.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #49413
    KevinKevin
    Participant

    Hi,

    I’m using the following group configuration:

    //GROUPES MEDICAMENTS
                [
                    'type' => 'group',
                    'tab' => 'medicaments',
                    'id' => 'liste_medicaments',
                    'clone' => true,
                    'add_button' => '+ Ajouter un nouveau médicament',
                    'sort_clone' => true,
                    'collapsible' => true,
                    //'save_state' => true, //Whether or not save the collapse/expand state?
                    'default_state'	=> 'collapsed', // or expanded (default).
                    'group_title' => 'Indication(s) {#} {medicament}',
                    'required'    => 1,
                    'fields' => [
                        [
                            'type' => 'group',
                            'id' => 'medicaments',
                            'clone' => true,
                            'add_button' => '+ Ajouter une ligne de médicament',
                            'required'    => 1,
                            'fields' => [
                                [
                                    'name' => __( 'Médicament', 'earlytrack' ),
                                    'id' => 'medicament',
                                    'type' => 'text',
                                    'columns' => 5,
                                ],
                                [
                                    'name' => __( 'Dosage', 'earlytrack' ),
                                    'id' => 'dosage',
                                    'type' => 'text',
                                    'columns' => 5,
                                ],
                                [
                                    'name' => __( 'Code UCD', 'earlytrack' ),
                                    'id' => 'code_ucd',
                                    'type' => 'text',
                                    'columns' => 2,
                                ],
                            ],
                        ],
                        [
                            'name' => __( 'Statut', 'earlytrack' ),
                            'id' => 'statut',
                            'type' => 'radio',
                            'options' => [
                                'AAP' => __( 'AAP', 'earlytrack' ),
                                'AAC très précoce' => __( 'AAC très précoce', 'earlytrack' ),
                                'CPC' => __( 'CPC', 'earlytrack' ),
                                'Autre' => __( 'Autre', 'earlytrack' ),
                            ],
                            'columns' => 6,
                        ],
                        //SI AUTRE
                        [
                            'name' => __('Préciser le statut (Autre)', 'earlytrack'),
                            'id' =>'autre_statut',
                            'type' => 'text',
                            'columns' => 6,
                            'visible' => [
                                'when' => [
                                    ['statut', '=', 'Autre'],
                                ],
                            ],
                        ],
                        [
                            'name' => __( 'Date d\'obtention', 'earlytrack' ),
                            'id' => 'date_obtention',
                            'type' => 'html5_date',
                            'date_type' => 'date',
                            'columns' => 12,
                        ],
                        [
                            'name' => __( 'Indication(s)', 'earlytrack' ),
                            'id' => 'indications',
                            'type' => 'textarea',
                            'columns' => 12,
                        ],
                        [
                            'name' => __( 'Nombre annuel de visites de suivi prévu au PUT', 'earlytrack' ),
                            'desc' => __( 'et autres indications, si nécessaire', 'earlytrack' ),
                            'id' => 'nombre_visites',
                            'type' => 'textarea',
                            'columns' => 6,
                        ],
                        [
                            'name' => __( 'Type de suivi', 'earlytrack' ),
                            'id' => 'type_suivi',
                            'type' => 'radio',
                            'options' => [
                                200 => __( 'Modéré (≤ 2 visites)', 'earlytrack' ),
                                500 => __( 'Soutenu (≥ 3 visites)', 'earlytrack' ),
                            ],
                            'columns' => 6,
                        ],
    
                    ],
                    'std' => get_post_meta( $nom_etude, 'liste_medicaments', true ) ?: [],
                ],

    As you can see on the last line, I’m setting the std value from a get_post_meta() call, coming from another frontend form, directly on the liste_medicaments group. (For context, $nom_etude is populated from $_GET['nom_etude'] and is working correctly with other forms.)

    The top-level std is applied as expected (it creates the correct number of liste_medicaments clones based on the initial form), but the nested group medicaments inside liste_medicaments is no longer populated with the saved data.

    This used to work fine with Meta Box AIO v2, but it stopped working from v3.0.1 onward. I waited for newer releases in case it was a bug, but even with v3.3.4 the behaviour is still the same.

    Could you please help me understand whether this is a regression, a breaking change in how std works with nested/cloneable groups, or if there’s now a different recommended way to pre-populate a nested group from get_post_meta()?

    #49427
    PeterPeter
    Moderator

    Hello Kevin,

    Thanks for reaching out.

    Can you please print out the value from this code get_post_meta( $nom_etude, 'liste_medicaments', true ) ?: [] ? I want to check if it has the correct structure as the field settings.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.