Un foro de discusión para nuestra comunidad de hispano hablante
By fardon
#789916
Hola, estoy intentando hacer una validacion en un grid, quiero validad que la cantidad enviada de productos no sea mayor a la disponible en bodega, tengo 6 bodegas.

Primero evaluo si el checkbox de disponible esta marcado, si es asi, evaluo a que operacion pertenece esa solicitud, si es igual a TEGUCIGALPA o TEGUCIGALPA/SN, hago un IF para comparar que la cantidad enviada no sea mayor a la disponible, si es verdadero me muestra una alerta.

Image

El problema es que me muestra la alerta cada vez que seleccione si esta disponible:

Image

Este es el codigo:
Code: Select all
var gridId = 'DescripcionProductos'; //set to the ID of the grid
//var operacion = $("#Operacion").getValue();
function setEmptyRowsToRed() {

    var aGridVals = $('#'+gridId).getValue();
    //loop through grid and check whether the "name" field is empty in each row
    for (i = 1; i <= aGridVals.length; i++) {
      
      //Tegucigalpa
      if ($("#DescripcionProductos").getValue(i, i + 9)[0] == "1") {
        
          
         if ($("#Operacion").getValue() == 'TEGUCIGALPA' || $("#Operacion").getValue() == 'TEGUCIGALPA/SN' ){
                
           if($("#form\\["+gridId+"\\]\\["+i+"\\]\\[CantidadEnviada\\]").val() > $("#form\\["+gridId+"\\]\\["+i+"\\]\\[Teg01\\]").val()){
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Teg01, verifiquelo."); 
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
           }
         }            
    }
      
       //Ocotepeque
       if ($("#DescripcionProductos").getValue(i, i + 9)[0] == "1") {
                
         if ($("#Operacion").getValue() == 'OCOTEPEQUE' ){
                
           if($("#form\\["+gridId+"\\]\\["+i+"\\]\\[CantidadEnviada\\]").val() > $("#form\\["+gridId+"\\]\\["+i+"\\]\\[Oco01\\]").val()){
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Oco01, verifiquelo."); 
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
              }
       }
             
       }
      
       //Comayagua
     if ($("#DescripcionProductos").getValue(i, i + 9)[0] == "1") {
        
          
         if ($("#Operacion").getValue() == 'COMAYAGUA'){
                
           if($("#form\\["+gridId+"\\]\\["+i+"\\]\\[CantidadEnviada\\]").val() > $("#form\\["+gridId+"\\]\\["+i+"\\]\\[Com01\\]").val()){
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Com01, verifiquelo."); 
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
           }
       }
             
       }
      /*--------------------------------------------------------------------------*/
      
      //SPS
       if ($("#DescripcionProductos").getValue(i, i + 9)[0] == "1") {
        
          
         if ($("#Operacion").getValue() == 'SAN PEDRO SULA'){
                
           if($("#form\\["+gridId+"\\]\\["+i+"\\]\\[CantidadEnviada\\]").val() > $("#form\\["+gridId+"\\]\\["+i+"\\]\\[Sps01\\]").val()){
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Sps01, verifiquelo."); 
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
              }
       }
             
       }
      /*--------------------------------------------------------------------------*/
      
      /*--------------------------------------------------------------------------*/
      
      //TALANGA
       if ($("#DescripcionProductos").getValue(i, i + 9)[0] == "1") {     
          
         if ($("#Operacion").getValue() == 'TALANGA' || $("#Operacion").getValue() == 'TALANGA/SN' ){
                
           if($("#form\\["+gridId+"\\]\\["+i+"\\]\\[CantidadEnviada\\]").val() > $("#form\\["+gridId+"\\]\\["+i+"\\]\\[Tal01\\]").val()){
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Tal01, verifiquelo."); 
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
              }
       }
             
       }
      /*--------------------------------------------------------------------------*/
      
      /*--------------------------------------------------------------------------*/
      
      //DANLI
     if ($("#DescripcionProductos").getValue(i, i + 9)[0] == "1") 
      {
          
        if ($("#Operacion").getValue() == 'DANLI '){
                
           if($("#form\\["+gridId+"\\]\\["+i+"\\]\\[CantidadEnviada\\]").val() > $("#form\\["+gridId+"\\]\\["+i+"\\]\\[Dan01\\]").val()){
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Dan01, verifiquelo."); 
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
              }
       }
             
       }
      /*--------------------------------------------------------------------------*/
      
      //OCOTEPEQUE
    }
}
           
                 
//execute when value in form changes:
$("form").setOnchange( function (fieldId, newVal, oldVal) {
   setEmptyRowsToRed();
});
User avatar
By amosbatto
#790011
¿Cuándo quieres mostrar el mensaje?
Puedes solo mostrar el mensaje mostrarlo cuando cambia el valor de "CantidadEnviada" asi:
Code: Select all
var gridId = 'DescripcionProductos'; //set to the ID of the grid
//var operacion = $("#Operacion").getValue();

function setEmptyRowsToRed(fieldId, newVal, oldVal) {
  var aMatches = fieldId.match(/\]\[(\d+)\]\[CantidadEnviada\]/)
  //if CantidadEnviada is changed in the grid:
  if (aMatches) {
    var rowNo = aMatches[1];   
    var aGridVals = $('#'+gridId).getValue();
      
    //Tegucigalpa      
    if ($("#Operacion").getValue() == 'TEGUCIGALPA' || $("#Operacion").getValue() == 'TEGUCIGALPA/SN' ){     
        if ($("#form\\["+gridId+"\\]\\["+rowNo+"\\]\\[Teg01\\]").val() == "1" && 
            parseFloat(newVal) > parseFloat($("#form\\["+gridId+"\\]\\["+rowNo+"\\]\\[Teg01\\]").val()) ) 
        {
         
              alert ("La cantidad Enviada no puede ser mayor a la Disponible en Teg01, verifiquelo.");
              jQuery("#DescripcionProductos").setValue("Favor ingresar datos correctos", i, i + 10);
        }           
    }
    //rest of your code here
}
                          
//execute when value in form changes:
$("form").setOnchange( setEmptyRowsToRed);

Web3 development encompasses creating decentralize[…]

The Upland Clone Script, offered by Dappsfirm, rep[…]

Dappsfirm offers a bet365 clone script that mirror[…]

🚀 Tauchen Sie mit Immediate Alora AI in die Welt d[…]