• Resolved hexagongirl

    (@hexagongirl)


    I’m trying to add a field value to an input in a group field – each time a new group row is added.

    This is what I’ve got so far; it does update the value, but the value is not displayed to the user. Any ideas why?

    Thanks!

        $('.cppg').find('.cmb-repeatable-group').on( 'cmb2_add_row', function( evt, row ) {
          var iteratorValue = row.data('iterator');
          var $idField = $(row).find('input:not([type="button"]), textarea, select').first();
          $idField.val(iteratorValue);
          $idField.css('background-color', 'red'); // this works fine
          console.log( $idField.val() ); // this works fine
        });
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Justin Sternberg

    (@jtsternberg)

    just tested, and worked for me. For reference, this is my code:

    add_action( 'admin_footer', function() {
    	?>
    	<script type="text/javascript">
    	( function( window, document, $, undefined ) {
    
    		var cb = function( evt, row ) {
    			var iteratorValue = row.data('iterator');
    			var $idField = $(row).find('input:not([type="button"]), textarea, select').first();
    			$idField.val(iteratorValue);
    			$idField.css('background-color', 'red'); // this works fine
    			console.log( $idField.val() ); // this works fine
    		};
    
    		$( document ).on( 'cmb_init', function() {
    			$('#cmb2-metabox-_yourprefix_group_metabox').find('.cmb-repeatable-group').on( 'cmb2_add_row', cb );
    		} );
    
    	} )( window, document, jQuery );
    	</script>
    	<?php
    } );
    
    Plugin Author Justin Sternberg

    (@jtsternberg)

    Screenshot after clicking the add button: https://b.ustin.co/JYwf

    Thread Starter hexagongirl

    (@hexagongirl)

    Many thanks Justin. I just needed to add it to the cmb_init hook.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamically update value of newly added group row’ is closed to new replies.