<?php
/***************************************** for time field ****************************************************************************/
//var_dump($field->type);
if ( $field->type === 'time' ) {

	$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' );
		}
	}

	foreach ( $all_divs as $container ) {
		$div_classes = $container->getAttribute( 'class' );
		if ( strpos( $div_classes, 'gfield_time_hour' ) !== false || strpos( $div_classes, 'gfield_time_minute' ) !== false ) {
			
			$container->setAttribute( 'class',
			$div_classes.' form-group'  );
			$inputs = $container->getElementsByTagName( 'input' );
			foreach ( $inputs as $input ) {
				$input_id = $input->getAttribute( 'id' );
				$input_type = $input->getAttribute( 'type' );
				//partial match id to make sure its the input we want to tag
				if ( strpos(  $input_id, 'input_' ) !== false && $input_type === 'text' ) {
					$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 ) );
			$content = utf8_decode($dom->saveHTML($dom->documentElement));
		}
	}
}
