Home Forums ACF PRO Programatically control Select2 fields Reply To: Programatically control Select2 fields

  • Thanks for the troubleshooting tips Jonathan. I made some tweaks to my selectors and with the following code was able to give the Select2 field focus when a new row is added.

    acf.add_action('append', function( $el ){
    	var $wood = $el.find( '[data-name="bulk_wood"] select');

    I’m still unable to set the value of the Select2 field though. This next snippets work as expected setting the value of text inputs using data from the previous row. Is it possible to set the value of a Taxonomy field type with the Select2 appearance? I think the AJAX parts are complicating this task.

    acf.add_action('append', function( $el ){
    	var $prev_row = $el.prev();
    	var $wood = $prev_row.find( '[data-name="bulk_wood"] select' ).val();
    	var $thickness = $prev_row.find( '[data-name="bulk_thickness"] input' ).val();
    	$el.find( '[data-name="bulk_thickness"] select' ).append(new Option('text', 'value')); // Not working
    	$el.find( '[data-name="bulk_thickness"] input' ).val( $thickness ); // Works great