0
I need to confirm some fields separately. It happens that it overwrites the text, does not wait for confirmation and only appears at the end of the last call and the confirmation of this, replicates to the previous ones. I don’t know what I can do to fix this.
var modalConfirm = function(callback) {
$("#gti-modal-btn-yes").click(function() {
callback(true);
$("#gti-modal").hide();
});
$("#gti-modal-btn-no").click(function() {
callback(false);
$("#gti-modal").hide();
});
$("#gti-modal-btn-close").click(function() {
callback(false);
$("#gti-modal").hide();
});
}
function modalAsk(msg, oldVal, newVal) {
$("#gti-modal-msg")[0].innerHTML = "<h3>" + msg + "</h3>";
$("#gti-modal").show();
modalConfirm(function(confirm) {
if (confirm) {
oldVal = newVal
alert('Change')
} else {
alert('No Change')
}
});
}
function funConfirmFields(fieldName, oldVal, newVal) {
if (newVal !== "") {
if (newVal !== oldVal) {
if (modalAsk('Atenção!</br>Campo: " ' + fieldName.toUpperCase() + '"</br>Valor atual: ' + oldVal + '</br>Novo Valor: ' + newVal + '</br></br>atualizar para o novo valor?')) {
newVal = oldVal
}
}
} else {
newVal = oldVal;
}
return newVal
}
$(document).ready(function() {
$("#txtNome")[0].value = funConfirmFields('Nome', $("#txtNome")[0].value, "b");
$("#txtDoc")[0].value = funConfirmFields('Doc', $("#txtDoc")[0].value, "2222");
$("#txtCel")[0].value = funConfirmFields('Cel', $("#txtCel")[0].value, "456");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div id="gti-modal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="gti-modal-Label" aria-hidden="false" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button id="gti-modal-btn-close" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<p id="gti-modal-titulo" class="modal-title"><i class='fa fa-question-circle pull-rigth '></i> MyModal </p>
</div>
<div id="gti-modal-msg" class="modal-body"></div>
<div class="modal-footer">
<button id="gti-modal-btn-yes" type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">yes</button>
<button id="gti-modal-btn-no" type="button" class="btn btn-primary">No</button>
</div>
</div>
</div>
</div>
<input class="form-control" type="text" id="txtNome" name="txtNome" value="a"/>
<input class="form-control" type="text" id="txtDoc" name="txtDoc" value= "111"/>
<input class="form-control" type="text" id="txtCel" name="txtCel" value= "123"/>
Hello Seafood is very welcome!! I did not understand very well what you want to do
– Thiago Costa
Thanks, I’m trying to confirm the altered fields one by one.. make a query via Soap and confrontation with what already exists on the screen the user must decide which information is correct
– Marisco