<?php

/***************************************** for list field **************************************/

if ( in_array( $field->type, $list_field ) ) {
	$contains_error = false;
	//check if error is present
	$all_divs = $dom->getElementsByTagName( 'div' );
	foreach ( $all_divs as $current_div ) {
		$current_div_classes = $current_div->getAttribute( 'class' );
		if ( strpos( $current_div_classes, 'validation_message' ) !== false ) {
			$contains_error = true;
			$current_div->setAttribute( 'class', $current_div->getAttribute( 'class').' invalid-feedback' );
		}
	}

	//add class to input
	$get_tds = $dom->getElementsByTagName( 'td' );


	foreach ( $get_tds as $td ) {
		$td_classes = $td->getAttribute( 'class' );
		if ( strpos( $td_classes, 'gfield_list_icons' ) === false ) {
			$td->setAttribute( 'class', $td_classes. ' form-group');
			$get_inputs = $td->getElementsByTagName('input');
			foreach( $get_inputs as $input){
				$input->setAttribute( 'class', $input->getAttribute('class'). ' form-control');
				if( $contains_error ){
					$input->setAttribute( 'class', $input->getAttribute('class'). ' is-invalid');
				}
			}
		}
	}
	$content = utf8_decode($dom->saveHTML($dom->documentElement));
}
