Title: REPEATABLE FIELDS TITLE NAME &amp; OPEN STATE
Last modified: March 17, 2019

---

# REPEATABLE FIELDS TITLE NAME & OPEN STATE

 *  Resolved [dkurth](https://wordpress.org/support/users/dkurth/)
 * (@dkurth)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/)
 * obscure question, but is there anyway I can change the repeatable record fields
   from “Record 1”, “Record 2” to something like one of my field values, if set?
   And to have all the repeatable fields closed, instead of open?
 * UPDATE:
    Found the closed state…by adding the ‘closed’=> true, to the group field
   type.
 * Now the question it is just the change title. In the same group field, I see 
   the “group title” with a number.
 * `'group_title' => __( 'Record {#}', 'mmd' ),`
 * what I would like is to put the value of one of my fields, or a call back, so
   I can place the value into that field.
 * Ideally:
 * `'group_title' => __( '{field-name}', 'mmd' ),`
 * But a call back to fill it, would also be most excellent.
    -  This topic was modified 7 years, 2 months ago by [dkurth](https://wordpress.org/support/users/dkurth/).
    -  This topic was modified 7 years, 2 months ago by [dkurth](https://wordpress.org/support/users/dkurth/).
    -  This topic was modified 7 years, 2 months ago by [dkurth](https://wordpress.org/support/users/dkurth/).

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

 *  Thread Starter [dkurth](https://wordpress.org/support/users/dkurth/)
 * (@dkurth)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323520)
 * Found this a few minutes ago…and posted in that question.
    [https://github.com/CMB2/CMB2-Snippet-Library/blob/master/javascript/dynamically-change-group-field-title-from-subfield.php](https://github.com/CMB2/CMB2-Snippet-Library/blob/master/javascript/dynamically-change-group-field-title-from-subfield.php)
 * I tried it, but it is not working. Do yo see anything incorrect?
 *     ```
       $group_field_id = $cmb->add_field( array(
       	'id'          => 'MMDListsRecord',
       	'type'        => 'group',
       	'description' => __( 'Individual Directory Listings', 'mmd' ),
       	'options'     => array(
       		'group_title'       => __( 'Record {#}', 'mmd' ), // since version 1.1.4, {#} gets replaced by row number
       		'add_button'        => __( 'Add Another Record', 'mmd' ),
       		'remove_button'     => __( 'Remove Record', 'mmd' ),
       		'sortable'          => true,
       		'closed'            => true,
       	),
         'after_group' => 'mmdlist_add_js_for_repeatable_titles',
       ) );
   
       function mmdlist_add_js_for_repeatable_titles() {
       	add_action( is_admin() ? 'admin_footer' : 'wp_footer', 'mmdlist_add_js_for_repeatable_titles_to_footer' );
       }
   
       function mmdlist_add_js_for_repeatable_titles_to_footer() {
       	?>
       	<script type="text/javascript">
       	jQuery( function( $ ) {
       		var $box = $( document.getElementById( 'MMDListsRecord' ) );
       		var replaceTitles = function() {
       			$box.find( '.cmb-group-title' ).each( function() {
       				var $this = $( this );
       				var txt = $this.next().find( '[id$="title"]' ).val();
       				var rowindex;
       				if ( ! txt ) {
       					txt = $box.find( '[data-grouptitle]' ).data( 'grouptitle' );
       					if ( txt ) {
       						rowindex = $this.parents( '[data-iterator]' ).data( 'iterator' );
       						txt = txt.replace( '{#}', ( rowindex + 1 ) );
       					}
       				}
       				if ( txt ) {
       					$this.text( txt );
       				}
       			});
       		};
       		var replaceOnKeyUp = function( evt ) {
       			var $this = $( evt.target );
       			var id = 'title';
       			if ( evt.target.id.indexOf(id, evt.target.id.length - id.length) !== -1 ) {
       				$this.parents( '.cmb-row.cmb-repeatable-grouping' ).find( '.cmb-group-title' ).text( $this.val() );
       			}
       		};
       		$box
       			.on( 'cmb2_add_row cmb2_remove_row cmb2_shift_rows_complete', replaceTitles )
       			.on( 'keyup', replaceOnKeyUp );
       		replaceTitles();
       	});
       	</script>
       	<?php
       }
       ```
   
 * I even tried adding the prefix to the call. Nothing. I must be missing something.
    -  This reply was modified 7 years, 2 months ago by [dkurth](https://wordpress.org/support/users/dkurth/).
    -  This reply was modified 7 years, 2 months ago by [dkurth](https://wordpress.org/support/users/dkurth/).
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323550)
 * `var $box = $( document.getElementById( 'MMDListsRecord' ) );` is wrong. the 
   ID there should be the box ID, not the group field ID.
 *  Thread Starter [dkurth](https://wordpress.org/support/users/dkurth/)
 * (@dkurth)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323571)
 * So the id of the field you want to use. Got it.
    Yet when I replace:
 *     ```
       var $box = $( document.getElementById( 'title' ) );'
   
       (the name of the field), nothing happens
       ```
   
 * Here is a sample of one of the group fields. The one I want to use.
 *     ```
       $cmb->add_group_field( $group_field_id, array(
       	                             'name'            => 'test',
       	                             'id'              => 'title',
       	                             'type'            => 'title',
       							  'sanitization_cb' => false,
       							  'escape_cb'       => false,
       							  'on_front'        => false,
   
                                   ) );  
       ```
   
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323589)
 * No, not the ID of the group field or the individual group sub-fields. The Box
   ID. So if you’re using [this snippet](https://gist.github.com/dskurth/d56744de4ae076c417f59b2a459eaf4b),
   then it would be `mmd_records_test`.
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323595)
 * Please review [the provided snippet](https://github.com/CMB2/CMB2-Snippet-Library/blob/master/javascript/dynamically-change-group-field-title-from-subfield.php)
   to see what I mean.
 *  Thread Starter [dkurth](https://wordpress.org/support/users/dkurth/)
 * (@dkurth)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323613)
 * BINGO! Thank you.
 * (See how language is different from one person to the next. When you showed in
   the sample “yourprefix_group_titles_metabox” I took that to be the group title
   id.
 *  Thread Starter [dkurth](https://wordpress.org/support/users/dkurth/)
 * (@dkurth)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323628)
 * Awesome job

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

The topic ‘REPEATABLE FIELDS TITLE NAME & OPEN STATE’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [dkurth](https://wordpress.org/support/users/dkurth/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/repeatable-fields-title-name-open-state/#post-11323628)
 * Status: resolved