1
I have a form, and a list of actions that the user can choose, depending on the action that was chosen, the user must confirm the submission, leave a message or simply send the form.
I have almost everything ready, what I’m not getting is to pick up when the user confirms this sending and the message left.
<form action="#" method="post" id="form-create">
<div class="form-group">
<label class="control-label" for="titulo">Titulo</label>
<input type="text" name="titulo" id="titulo" class="form-control" maxlength="255"/>
</div>
<div class="form-group">
<label class="control-label">Ação</label>
<div class="radio">
<label>
<input type="radio" name="actionFormDoc" value="1" data-tipo-mensagem="null" data-label="Manter" /> Manter
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="actionFormDoc" value="2" data-tipo-mensagem="message" data-label="Salvar" /> Salvar
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="actionFormDoc" value="3" data-tipo-mensagem="confirm" data-label="Finalizar" /> Finalizar
</label>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" id="save" value="Salvar" />
</div>
</form>
<!-- MODALS -->
<div id="message" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModelMessage" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Envie uma mensagem de observação</h4>
</div>
<div class="modal-body">
<textarea name="obs" id="obs" rows="3" class="form-control"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" id="sendMessage">Enviar</button>
</div>
</div>
</div>
</div>
<div id="confirm" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModelConfirm" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirmar ação?</h4>
</div>
<div class="modal-body">
Confirmar ação?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Não</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" id="confirmado">Sim</button>
</div>
</div>
</div>
</div>
and javascript
$( function() {
var formCreate = $("form#form-create");
$("#save").click(function(event) {
event.preventDefault();
var tipoMensagem = $('input[name="actionFormDoc"]:checked').data('tipo-mensagem');
var valMensagem = $('input[name="actionFormDoc"]:checked').data('label');
var sendConfirm = false;
if (tipoMensagem == 'confirm') {
$('#confirm .modal-body').text('Deseja realmente ' +valMensagem+ ' o documento?')
$('#confirm').modal()
.one('click', '#confirmado', function (e) {
sendConfirm = true;
});
}
if (tipoMensagem == 'message') {
$('#message').modal()
.one('click', '#sendMessage', function (e) {
sendConfirm = true;
});
}
if (tipoMensagem == 'null') {
sendConfirm = true;
}
if (sendConfirm == true) {
formCreate.submit();
}
});
});
Sergio, these changes you suggested have already helped me, I just don’t understand why the buttons to close the modal stopped working.
– Marcelo Diniz
@Marcelodiniz when using
$('#message').modal().off()
this removes all event headphones. Test like this: http://jsfiddle.net/1zhq5rk3/2/. Works?– Sergio
I ended up solving this: http://jsfiddle.net/marcelod/1hbLL8an/ this whole question, yet I graduate your help.
– Marcelo Diniz
@Marcelodiniz is great. If you think my answer helped solve the problem you can mark it as accepted, if you can’t give an answer explaining what worked.
– Sergio