alleyinteractive / alleyinteractive/wordpress-fieldmanager

Unchecked checkbox in repeating group won't save

Aberta
#487 2 comentários 0 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
PHP
Estrelas
563
Forks
99
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

If you create a checkbox with a default value `true` (checked) within a repeating field group, Fieldmanager fails to save the checkbox state when unchecked, even if '`save_empty'` is set `true`.

You can work around this issue by setting `'false_value'` to `'no'`, however setting `'false_value'` to `0` does not work around the issue.

A test implementation follows. The desired outcome is that when you uncheck an instance of the checkbox `'in_repeating_group'` and save the post, the fact that the box was not checked should be saved.

``` php
function ai_fm_checkbox_test() {
$fm = new Fieldmanager_Group( array(
'name' => 'checkbox-test',
'serialize_data' => false,
'add_to_prefix' => false,
'children' => array(
'not_in_group' => new Fieldmanager_Checkbox( array(
'label' => __( 'Not in a group', 'ai' ),
'default_value' => true,
'save_empty' => true,
'description' => __( 'This saves fine', 'ai' ),
) ),
'group' => new Fieldmanager_Group( array(
'label' => __( 'Group', 'ai' ),
'children' => array(
'in_group' => new Fieldmanager_Checkbox( array(
'label' => __( 'In a group', 'ai' ),
'default_value' => true,
'save_empty' => true,
'description' => __( 'This saves fine', 'ai' ),
) ),
),
) ),
'repeating_group' => new Fieldmanager_Group( array(
'label' => __( 'Repeating Group', 'ai' ),
'limit' => 0,
'children' => array(
'in_repeating_group' => new Fieldmanager_Checkbox( array(
'label' => __( 'In a group', 'ai' ),
'default_value' => true,
'save_empty' => true,
'description' => __( 'This checkbox does not save if unchecked', 'ai' ),
) ),
'text' => new Fieldmanager_TextField( array(
'label' => __( 'Text field', 'ai' ),
'description' => __( 'Even if the group is not empty, an unchecked checkbox does not save.', 'ai' ),
) ),
),
) ),
),
) );
$fm->add_meta_box( __( 'Unsaved checkbox test', 'ai' ), array( 'post' ), 'normal', 'default' );
}
add_action( 'fm_post_post', 'ai_fm_checkbox_test' );
```

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.