Dynamic form showing value that was not meant to show

Asked

Viewed 56 times

1

Talk to the guys, all right? When I create a dynamic form, it defaults to select, an empty Value in the option, which is set to Value="N/A". When I add, for example, two dynamic forms to fill, when displaying in the content it shows one that was not requested, such as N/A.

In the image, I filled out only two dynamic Interrupt forms, Equipment Outage and Test Area (I put Start and Finish as N/A itself). But he added a call N/A, as in the first image.

O que mostra na tela

Here is the form: Formulário

Here are the codes:

$(document).ready(function(){
    //group add limit
    var maxGroup = 10;
    
    //add more fields group
    $(".addMore").click(function(){
    	if($('body').find('.fieldGroup').length < maxGroup){
    		var fieldHTML = '<div class="form-group fieldGroup">'+$(".fieldGroupCopy").html()+'</div>';
    		$('body').find('.fieldGroup:last').after(fieldHTML);
    	}else{
    		alert('Maximum '+maxGroup+' groups are allowed.');
    	}
    });
    
    //remove fields group
    $("body").on("click",".remove",function(){ 
    	$(this).parents(".fieldGroup").remove();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="panel-heading"><b>Interrupções</b></div>
<div class="intcont">
	<div class="form-group fieldGroup">
		<div class="input-group">
			<select required="" class="form-control" id="interrupcao" name="interrupcao[]">
				<option value="N/A">Motivo</option>
				<option value="Indisponibilidade de equipamentos">Indisponibilidade de equipamentos</option>
				<option value="Indisponibilidade de Área de teste">Indisponibilidade de Área de teste</option>
				<option value="Outros (Descrever em Comentários)">Outros (Descrever em Comentários)</option>
			</select>
			<input required="" value="N/A" type="text" name="inicioint[]" class="form-control" placeholder="Início"/>
			<input required="" value="N/A" type="text" name="terminoint[]" class="form-control" placeholder="Término"/>
			<div class="input-group-addon"> 
				<a href="javascript:void(0)" class="btn btn-primary addMore"><span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span></a>
			</div>
		</div>
	</div>
	
	<!-- Cópia do formulário pra gerar em baixo -->
	<div class="form-group fieldGroupCopy" style="display: none;">
		<div class="input-group">
			<select required="" class="form-control" id="interrupcao" name="interrupcao[]">
				<option value="N/A">Motivo</option>
				<option value="Indisponibilidade de equipamentos">Indisponibilidade de equipamentos</option>
				<option value="Indisponibilidade de Área de teste">Indisponibilidade de Área de teste</option>
				<option value="Outros (Descrever em Comentários)">Outros (Descrever em Comentários)</option>
			</select>
			<input required="" value="N/A" type="text" name="inicioint[]" class="form-control" placeholder="Início"/>
			<input required="" value="N/A" type="text" name="terminoint[]" class="form-control" placeholder="Término"/>
			<div class="input-group-addon"> 
				<a href="javascript:void(0)" class="btn btn-danger remove"><span class="glyphicon glyphicon glyphicon-remove" aria-hidden="true"></span></a>
			</div>
		</div>
	</div>
</div>
<button class="addMore">add</button>

And here is the code that will show in a PDF the interruptions:

  $html .= "<table>";
  $html .= "<tr>";
  $html .= "<th>INTERRUPÇÕES</th>";
  $html .= "<th>Início</th>";
  $html .= "<th>Término</th>";
  $html .= "</tr>";

  for ($i=0; $i < count($_POST['interrupcao']); $i++) {

   $html .="<tr>";
   $html .="<td>{$_POST['interrupcao'][$i]}</td>";
   $html .="<td>{$_POST['inicioint'][$i]}</td>";
   $html .="<td>{$_POST['terminoint'][$i]}</td>";
   $html .= "</tr>";

  }
  $html .= "</table>";
  • I can’t visualize that supposed mistake

  • Your question seems a little incomplete. It does not show how to get to this screen of the print you posted on the question, and the code you posted does not show any error.

  • When displaying the form values, it shows this N/A, as in the image, and I did not register a form with this value.

  • Besides the jquery library which others you are using, and the CSS? On my server you are different http://kithomepage.com/sos/valor-na.htm

  • And how do you get the first image? what is the code? With what you posted you can not test.

  • Edited, I put a snippet that displays the added interrupts in the form, but you add this N/A when displaying =p

  • In the code you put of example the error does not occur

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.