• Resolved happyfox094

    (@happyfox094)


    Hello. I’ve been trying to make “render_row_cb” work, because I want to input the row and the input html myself, I cannot make it work. When I copy the example code from the documentation, it does not render the row itself, it only renders the string “cmb_test_render_row_cb”, and that’s it. Here my code.

    $cmb->add_field( array(
    			'name' => 'Test render_row_cb (manaully rendered)',
    			'desc' => 'field description (optional)',
    			'id'   => 'wiki_testrender_row_cb',
    			'type' => 'text',
    			'render_row_cb' => 'cmb_test_render_row_cb',
    		) );
    
    public function cmb_test_render_row_cb( $field_args, $field ) {
    		$id          = $field->args( 'id' );
    		$label       = $field->args( 'name' );
    		$name        = $field->args( '_name' );
    		$value       = $field->escaped_value();
    		$description = $field->args( 'description' );
    		?>
    		<div class="custom-field-row">
    			<p><label for="<?php echo $id; ?>"><?php echo $label; ?></label></p>
    			<p><input id="<?php echo $id; ?>" type="text" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/></p>
    			<p class="description"><?php echo $description; ?></p>
    		</div>
    		<?php
    	}

    Now I see it says “This is mainly to edit the markup that surrounds each individual field, not to edit the field itself.”. How to edit tie fields itself? I just have a select and I want to add data attributes on each OPTION, not on the select itself, on each option.
    Ex: <option value="test" data-num="1">Teest</option>

    • This topic was modified 6 years, 10 months ago by happyfox094.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If all your code here is part of a PHP class, then you need to reference the cmb_test_render_row_cb method this way:

    'render_row_cb' => array( $this, 'cmb_test_render_row_cb' ),

    The way you have it, it’s looking for a function outside of the class named cmb_test_render_row_cb but it’s not finding any defined functions like that, so it’s ending up being interpreted as a string, I do believe.

    Thread Starter happyfox094

    (@happyfox094)

    Thank you very much, it works like a charm!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

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

The topic ‘Cannon make “render_row_cb” work’ is closed to new replies.