The first is executed first and is responsible for reading the html to save data in a two-dimensional array (javascript), but before saving the data in the array
desire to validate it if it is null
empty ( so far without problems).
For this one asyn
and await
. As there are several columns to save in my array
use several await
to validate data by data , but my problem is that only await
the first validation works and the software does not advance further.
This is my first function:
for(var a=0;a<elementos_variantes.length; a++)
{
datos[a]= new Array();
}
// Recopilacion de datos
for(var b=0;b<elementos_variantes.length; b++)
{
datos[b][0]=await validar_datos($("." + elementos_variantes[b] + '.select_bodega').val());
datos[b][1]=await validar_datos($("." + elementos_variantes[b] + '.select_producto').val());
datos[b][2]=await validar_datos($("." + elementos_variantes[b] + '.select_variante').val());
datos[b][3]=await validar_datos($('.ca' + elementos_variantes[b]).val());
}
This is the function that validates data by data:
function validar_datos(dato)
{
return new Promise(resolve => {
if(dato=='undefined' || dato==null || dato=="")
{
Swal.fire({
icon: 'error',
title: 'Informacion',
text: 'Llene todos los datos.'
});
return;
}
else
{
return dato;
}
});
}
As I mentioned before , it only does the first validation even though the first data to be validated is neither null
, undefined
nor empty , it only validates this:
datos[b][0]=await validar_datos($("." + elementos_variantes[b] + '.select_bodega').val());
and there it stops and does not continue with the following validations.