I have the following fields:
TheselectwillcontainRGandCPF.HowcanIdothatwhenselectingtheCPF,thefieldchangestowhathasmask?ThefieldthatcontainsthemaskIhaveready,Ijustneedtoincludeitinthischange.
Seethecode:
<tableborder="0" width="100%">
<tr class='linhas'>
<td style="padding: 5px"><input type="text" name="NomePAX[]" class="form-control" placeholder="Nome do pax" value=""></td>
<td style="padding: 5px">
<select name="TipoDocumento" class="form-control">
<option>Selecione o tipo de documento</option>
</select>
</td>
<td style="padding: 5px">
<input type="text" name="RGPessoaAutorizada[]" class="form-control" placeholder="RG da pessoa autorizada" value="">
<!-- Caso escolha o CPF, desabilite o campo acima e mostre o campo abaixo -->
<input type="text" name="CPF[]" id="cpf" class="form-control" data-inputmask="'alias': '999.999.999-99'">
</td>
<td style="padding: 5px"><button type="button" class="removerCampo btn btn-danger" title="Remover linha"><i class="fa fa-minus-square" aria-hidden="true"></i> Remover</button></td>
</tr>
<tr>
<td colspan="3"><button type="button" class="adicionarCampo btn btn-primary" title="Adicionar item"><i class="fa fa-plus-square" aria-hidden="true"></i> Adicionar mais passageiros</button></td>
</tr>
</table>
JQuery
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
if ($('.linhas').length < 15) {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find('input[type="text"]').val("");
novoCampo.find('select').val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
}
});
});
</script>