Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display Checkbox values Vertically on Profile


  • nhorstmann
    Participant

    @nhorstmann

    I have field groups with multiple checkboxes for users to keep track of their progress with. When they view their profile, I would like these to be displayed in a vertical list.

    Right now under character development, the user has read 2 of the books, it displays them side by side rather than putting a line break between them.

    is there an easy way to fix this?

Viewing 2 replies - 1 through 2 (of 2 total)

  • Varun Dubey
    Participant

    @vapvarun

    @nhorstmann all the values are getting printed as comma separated values

    You can add following codes inside child theme function.php and then it will add a span to them base on field type and you can add css for them.

    add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_add_class_profile_data',          9, 3 );
    function xprofile_filter_add_class_profile_data( $field_value, $field_type = 'textbox' ) {
    	global $field,$bp;
    
    	
    	if ( 'datebox' === $field_type ) {
    		return $field_value;
    	}
    
    	if ( strpos( $field_value, ',' ) === false ) {
    		return $field_value;
    	}
    
    	if ( strpos( $field_value, ',' ) !== false ) {
    		// Comma-separated lists.
    		$list_type = 'comma';
    		$values    = explode( ',', $field_value );
    	}
    
    	if ( ! empty( $values ) ) {
    		foreach ( (array) $values as $value ) {
    			$value = trim( $value );
    		    $new_values[] = '<span class="value-' . $field_type . '">' . $value . '</span>';
    		}
    
    		if ( 'comma' === $list_type ) {
    			$values = implode( '  ', $new_values );
    		} 
    	}
    
    	return $values;
    }

    nhorstmann
    Participant

    @nhorstmann

    Hey @vapvarun,

    Thanks for the help, but this didn’t seem to add a span, here is the code im seeing after adding this to the function.php file

    <tr class="field_77 field_communication optional-field visibility-adminsonly alt field_type_checkbox">
       <td class="label">Communication</td>
       <td class="data"><p>COURSE: C4 Communication, BOOK: Made To Stick by Chip and Dan Heath</p>
       </td>
    </tr>

    Never mind, got it working! Thanks so much. I didn’t notice when I pasted it in that the first line was commented out.

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