I'm using jquery $ .when () to wait for all requests to be made. The problem is: I can not return a boolean for my function.
The flow is: Execute the functions and return a true that my main function is waiting for.
function PreSaveItem()
{
$.when($.ajax( uploadFile()) ).then(function( data, textStatus, jqXHR) {
console.log("caiu aqui 2");
});
}
I've tested three options:
Place true at the end of the function uploadFile or in my own PreSaveItem function.
If I put a return $ .when always returns true and is not what I want, as can be seen below, with validations returning false:
function uploadFile() {
if(!needUpload) /* etapas de aprovacao de departamentos */
return true;
if($('#getFile').val() == ""){
alert("Nenhum anexo inserido");
return false;
}
/* valida se o documento é pdf */
if($('#getFile').val().lastIndexOf(".pdf") == -1){
alert("O documento deve ser um PDF");
return false;
}
var getFile = getFileBuffer();
getFile.then(function (arrayBuffer) {
// Adiciona o arquivo para a pasta do contrato
var addFile = addFileToFolder(arrayBuffer);
addFile.then(function (file, status, xhr) {
var insertedDocumentId = file.d.ListItemAllFields.ID;
var retorno_callupdate = callUpdateFunction(lisTitle,
insertedDocumentId, contentTypeId);
});
});
}