alleyinteractive / alleyinteractive/wordpress-fieldmanager

Using `display_if` with unconnected fields

Aperta
#752 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement scope:display-if
Lingua principale
PHP
Stelle
563
Fork
99
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I have 2 groups and am trying to show/hide a field in the 2nd group based on a value of a field in the 1st group. But the 2nd group is not able to get the field value from the first group!
It works when I move the dependent field into the first group (where the deciding field exists) but due to the complex structure of the fields on my editor, I am not able to move them all into a single group.

Is there a way around this or a way to share field values between groups?
eg.
```
// a simplified example - which doesnt work. module_t1 should disappear until the _wp_page_template value is `page-dynamail-goods.php`

// first group
$group = new Fieldmanager_Group(
array(
'label' => false,
'name' => 'dynamail_content',
'add_to_prefix' => false,
'serialize_data' => false,
)
);
$group->add_child(
new Fieldmanager_Select(
array(
'label' => __( 'Template', 'test-platform' ),
'name' => '_wp_page_template',
'first_empty' => true,
'options' => Template::build_select_list(),
)
)
);
$group->add_child(
new Fieldmanager_Textfield(
array(
'label' => __( 'Partner Name', 'test-platform' ),
'name' => 'partner_name',
)
)
);
$group->add_meta_box( __( 'Email Content', 'test-platform' ), Content_Model::DYNAMAIL_POST_TYPE );

// 2nd group
$group1 = new Fieldmanager_Group(
array(
'label' => false,
'name' => 'dynamail_test',
'add_to_prefix' => false,
'serialize_data' => false,
)
);

$group1->add_child(
new Fieldmanager_Checkbox( array(
'label' => 'test1',
'name' => 'module_t1',
'display_if' => array(
'src' => '_wp_page_template',
'value' => 'page-dynamail-goods.php',

),
) )
);
$group1->add_meta_box( __( 'Email Test', 'test-platform' ), Content_Model::DYNAMAIL_POST_TYPE );
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.