wordpress-fieldmanager
wordpress-fieldmanager copied to clipboard
Can't delete repeater items
We have a repeater field group and when a user tries to delete items in the field group, when they click update the fields return:
https://cl.ly/2e1H3H0n3s34
I have noticed that Fieldmanager_Field::prevsave_all() Compares the saved value with the new value from $_POST. If the new $_POST value is smaller than the old one it adds another item to the values array which results in an empty item being added to the meta data, even if that item has been deleted.
If i comment out this loop it works as you would expect.
The field group is a group within a group, here is an example of how the field is init:
$fm = new Fieldmanager_Group(
array(
'name' => 'secondary-highlight-sections',
'children' => array(
'title' => new Fieldmanager_TextArea(
esc_html_x( 'Section Title', 'field manager label', 'fbmpl-plugin-domain' ),
array(
'attributes' => array(
'rows' => 4,
'cols' => 180,
),
)
),
'items' => new Fieldmanager_Group( array(
'limit' => 0,
'minimum_count' => 0,
'extra_elements' => 0,
'sortable' => 1,
'add_more_label' => esc_html_x( 'Add Content', 'field manager label', 'fbmpl-plugin-domain' ),
'sortable' => true,
'label' => esc_html_x( 'Section', 'field manager label', 'fbmpl-plugin-domain' ),
'children' => array(
'media' => Fbmpl_Field_Manager_Shared::render_media_group( esc_html_x( 'Item Image', 'field manager label', 'fbmpl-plugin-domain' ), 'image' ),
'title' => new Fieldmanager_TextArea(
esc_html_x( 'Item Title', 'field manager label', 'fbmpl-plugin-domain' ),
array(
'attributes' => array(
'rows' => 4,
'cols' => 180,
),
)
),
'content' => new Fieldmanager_TextArea(
esc_html_x( 'Item Content', 'field manager label', 'fbmpl-plugin-domain' ),
array(
'attributes' => array(
'rows' => 4,
'cols' => 180,
),
)
),
'ctas' => new Fieldmanager_Group( array(
'limit' => 0,
'minimum_count' => 0,
'extra_elements' => 0,
'sortable' => 1,
'add_more_label' => esc_html_x( 'Add Call to Action', 'field manager label', 'fbmpl-plugin-domain' ),
'sortable' => true,
'label' => esc_html_x( 'Call to Action', 'field manager label', 'fbmpl-plugin-domain' ),
'children' => array(
'cta' => Fbmpl_Field_Manager_Shared::render_call_to_action_group( esc_html_x( 'CTA Item', 'field manager label', 'fbmpl-plugin-domain' ), $cta_search_cpts ),
),
) ),
),
) ),
),
)
);
$fm->add_meta_box( $metabox_title, 'page' );