Skip to content

Add field setting to enable CSV display mode for checkbox fields #2404

@zackkatz

Description

@zackkatz

Summary

Add a field setting to enable CSV (comma-separated) display mode for checkbox fields, eliminating the need for users to manually add custom code via filters.

Current Situation

Currently, users who want to display checkbox field values as comma-separated text instead of the default bulleted list must add custom code to their theme's functions.php file or create a custom plugin using the gravityview/template/field/checkbox/output filter.

Current workaround requires:

add_filter( 'gravityview/template/field/checkbox/output', function( $output, $context ) {
    $value = $context->value;
    
    if ( is_array( $value ) ) {
        // Convert array to comma-separated string
        $value = array_filter( $value, function( $item ) {
            return '' !== $item;
        });
        $output = implode( ', ', $value );
    }
    
    return $output;
}, 10, 2 );

Proposed Solution

Add a new field setting option to the checkbox field configuration that allows users to choose between:

  1. Default - Current bulleted list display
  2. CSV - Comma-separated values display

Implementation Details

Field Setting Addition

  • Add new radio button option to the checkbox field settings in the "Display" group
  • Similar to existing choice_display setting pattern
  • Should be available for the parent checkbox field (not individual inputs)

Setting Configuration

$field_options['display_format'] = array(
    'type'     => 'radio',
    'class'    => 'vertical',
    'label'    => __( 'Display Format:', 'gk-gravityview' ),
    'value'    => 'default',
    'choices'  => array(
        'default' => __( 'Bulleted list (default)', 'gk-gravityview' ),
        'csv'     => __( 'Comma-separated values', 'gk-gravityview' ),
    ),
    'group'    => 'display',
    'priority' => 110,
);

Template Logic Update

Update templates/fields/field-checkbox-html.php to check for the new setting and apply CSV formatting when selected.

Technical Requirements

Files to Modify

  1. includes/fields/class-gravityview-field-checkbox.php - Add field setting
  2. templates/fields/field-checkbox-html.php - Add display logic

Backward Compatibility

  • Default behavior remains unchanged (bulleted list)
  • Existing custom filter implementations continue to work
  • New setting only affects display when explicitly selected

User Experience

  • Setting should only appear for parent checkbox fields (not individual checkbox inputs)
  • Clear labeling to indicate the difference between display formats
  • Should work with existing choice_display setting combinations

Benefits

  1. User-Friendly - No code required, accessible through admin interface
  2. Backward Compatible - Doesn't affect existing implementations
  3. Consistent - Follows existing field setting patterns in GravityView
  4. Maintainable - Built into core functionality rather than requiring custom code

Acceptance Criteria

  • New field setting appears in checkbox field configuration
  • Setting only shows for parent checkbox fields (not individual inputs)
  • CSV option displays values as comma-separated text
  • Default option maintains current bulleted list behavior
  • Works with all existing choice_display options (value, label, tick)
  • Backward compatibility maintained
  • Setting follows existing UI patterns and styling

Related Documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions