0
I have that code:
function loadEditLabel() {
// Salva o novo input saindo do campo ou apertando enter
$('[contenteditable="true"]').focus().select().keydown(function(event) {
if (event.key == 'Enter') { // Checa se a tecla digitada foi o Enter
$(this).prev('input').val(this.innerHTML); // Colocar o value do input com o texto digitado
$(this).prop('contenteditable', false); // Desabilita o campo de edição
}
})
.blur(function() {
$(this).prev('input').val(this.innerHTML);
$(this).prop('contenteditable', false);
});
}
$('#add').click(function() {
html = '<div>';
html += '<input type="radio" style="vertical-align: text-bottom;" value="teste" name="data">';
html += '<input type="text" placeholder="Nova Entrada">';
html += '</div>';
$('#radios').append(html); // Adiciona o novo input dentro da div radios
loadEditLabel(); // Carrega o radio para a edição
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group esconder" id="id_2">
<div class="panel panel-default">
<div class="panel-body">
<div id="multipla-escolha">
<label class="" for="orderBy">Pergunta</label>
<input class="form-control " type="text" placeholder="Pergunta">
<div class="container">
<div id="radios">
<div>
<input type="radio" style="vertical-align: text-bottom;" value="teste" name="data"><input type="text" value="Opção 1">
</div>
</div>
<button id="add">+</button>
</div>
</div>
</div>
</div>
</div>
It serves to add radios, but only that it should add only when clicked on button, only any click that I give, including on other pages, add radio to this modal dialog.
If you run the code presented in the question, you will see that the new element is only added by clicking the button
+, then have as [Edit] the question and better detail the problem?– Woss
I put an Alert in the js function, and it gives Alert in any clicks I give from the modal fade, IE, this click ta is adding the radios. I don’t know why, but this click that should be exclusive to the add button, is running when I click any type
– Isa