• Resolved dkurth

    (@dkurth)


    Is there a way to add more functional buttons to the form? It would sit next to the “Add Another Record” button presently in existence.

    My goal is to limit the number of records loaded at any one time and know “which” record to start loading at, using a cookie. Just need to know how to add about 3 buttons. I can write the Javascript.

    • This topic was modified 5 years, 5 months ago by dkurth.
    • This topic was modified 5 years, 5 months ago by dkurth.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter dkurth

    (@dkurth)

    Just a FYI, I have been trying to modify the code in CMB2_Types, line 344, just to duplicate the same button and it function, just displaying 2 buttons instead of one. It is within the function

    	public function render_repeatable_field() {
    		$table_id = $this->field->id() . '_repeat';
    
    		$this->_desc( true, true, true );
    		?>
    
    		<div id="<?php echo $table_id; ?>" class="cmb-repeat-table cmb-nested">
    			<div class="cmb-tbody cmb-field-list">
    				<?php $this->repeatable_rows(); ?>
    			</div>
    		</div>
    		<p class="cmb-add-row">
    			<button type="button" data-selector="<?php echo $table_id; ?>" class="cmb-add-row-button button-secondary"><?php echo esc_html( $this->_text( 'add_row_text', esc_html__( 'Add Row', 'cmb2' ) ) ); ?></button>
    		</p> <strong>this is a test<br />   << ===== I ADDED THIS</strong>
    		<?php
    		// reset iterator
    		$this->iterator = 0;
    	} 

    But nothing displays and I honestly, at this point, do not know why. No where else seems to have the same class calls.

    What am I missing?

    Thread Starter dkurth

    (@dkurth)

    Interesting…found it in a different file (CMB2.php) Can you tell me what that other function is for? And since I normally use a ‘onclick’ feature and do not see that in the function below, can you educate me or point me to how this ‘data-selector feature appears to work? That is totally new.

    	public function render_group_callback( $field_args, $field_group ) {
    
    		// If field is requesting to be conditionally shown.
    		if ( ! $field_group || ! $field_group->should_show() ) {
    			return;
    		}
    
    		$field_group->index = 0;
    
    		$field_group->peform_param_callback( 'before_group' );
    
    		$desc      = $field_group->args( 'description' );
    		$label     = $field_group->args( 'name' );
    		$group_val = (array) $field_group->value();
    
    		echo '<div class="cmb-row cmb-repeat-group-wrap ', esc_attr( $field_group->row_classes() ), '" data-fieldtype="group"><div class="cmb-td"><div data-groupid="', esc_attr( $field_group->id() ), '" id="', esc_attr( $field_group->id() ), '_repeat" ', $this->group_wrap_attributes( $field_group ), '>';
    
    		if ( $desc || $label ) {
    			$class = $desc ? ' cmb-group-description' : '';
    			echo '<div class="cmb-row', $class, '"><div class="cmb-th">';
    			if ( $label ) {
    				echo '<h2 class="cmb-group-name">', $label, '</h2>';
    			}
    			if ( $desc ) {
    				echo '<p class="cmb2-metabox-description">', $desc, '</p>';
    			}
    			echo '</div></div>';
    		}
    
    		if ( ! empty( $group_val ) ) {
    			foreach ( $group_val as $group_key => $field_id ) {
    				$this->render_group_row( $field_group );
    				$field_group->index++;
    			}
    		} else {
    			$this->render_group_row( $field_group );
    		}
    
    		if ( $field_group->args( 'repeatable' ) ) {
    			echo '<div class="cmb-row"><div class="cmb-td"><p class="cmb-add-row"><button type="button" data-selector="', esc_attr( $field_group->id() ), '_repeat" data-grouptitle="', esc_attr( $field_group->options( 'group_title' ) ), '" class="cmb-add-group-row button-secondary">', $field_group->options( 'add_button' ), '</button></p></div></div>';
    	
    		}
    
    		echo '</div></div></div>';
    
    		$field_group->peform_param_callback( 'after_group' );
    
    		return $field_group;
    	}
    
    • This reply was modified 5 years, 5 months ago by dkurth.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I imagine the function names generally state what they’re for. For example, render_repeatable_field() is probably a helper function to render whatever repeatable fields are found. render_group_callback() would be potentially using the first one as part of the group it’s rendering at that time, piecing it all together.

    Guess my initial question would be what are the extra buttons for, just in case it affects responses at all. How involved would they be with the form submission process, etc. or are they just to reset the fields as an example.

    Thread Starter dkurth

    (@dkurth)

    ok, that is what I needed to know…what are the functions called.

    Here is what I am doing. I have hundreds of records in one list type that I am filling in the fields via override and database retrieval of information. (works great btw). BUT, when the number of records gets large and the size of each record is equally large, I want to limit the number of records that are displayed on the back end at any one time, yet still give access to the full list. Instead of say 150, display only 10 at a time.

    Using a cookie, I will keep track of the “top of the list” and know where to start loading the data from, in the database. The buttons would execute two items, the top of the list being displayed AND force the custom data callback to be re-executed.

    add_filter('cmb2_override_MMDListsRecord_meta_value', 'mmd_get_methods_custom_data', 10, 4);
    function mmd_get_methods_custom_data( $dont_override, $PostId,  $args, $cmb2_field_object )
    

    It is this last stage, to force the override call to be executed again, that I need assistance with…unless I just call it. (Have not tried that yet).

    The goal is to reduce the memory load for each of the lists that I am displaying in the admin section. The front end is no problem, since that is per account and will be just a few listings at a time. But the admin, can take upwards of 2 minutes to load..it is that large.

    • This reply was modified 5 years, 5 months ago by dkurth.
    Thread Starter dkurth

    (@dkurth)

    …too large. Each record is VERY big.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m checking internally for suggestions to provide, as I’m not completely sure myself, I’ve never added new buttons to the forms.

    Only idea I have off the top of my head is perhaps utilize some javascript to add them and go from there. However, hopefully I’ll get some more potential leads soon that i can pass along.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Other suggested method that I heard back about was replacing the render callback via https://github.com/CMB2/CMB2/wiki/Field-Parameters#render_row_cb It may not be exactly right next to the submit button, but I believe it could be any arbitrary field you want that you don’t even end up using since you render it with completely different markup for the sake of some buttons.

    Thread Starter dkurth

    (@dkurth)

    sorry for the delay, took a slightly different route by setting up separate custom post types that pull records from the database based on type verses one combined. If I still need this, I will get back to you…will post another question different subject.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds good.

    Thread Starter dkurth

    (@dkurth)

    wrote my own

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Add additional buttons?’ is closed to new replies.