sql >> Base de Datos >  >> RDS >> Oracle

¿Cómo realizar la validación fila por fila en un formulario Oracle APEX Tabular usando Ajax?

Como intentaría solucionarlo. Tenga en cuenta que esto no cubre todas las eventualidades (¿alguna?) o gran parte del manejo de errores. Tendrás que elaborarlo un poco tú mismo. por ejemplo, utilicé la entrada para un selector, necesitará "seleccionar". Las matrices pueden no coincidir. Es posible que necesite un selector completamente diferente, como td[headers]. Tal vez su objeto devuelto deba contener otros o más valores. Es posible que su js necesite más expansión.
Sin embargo, ¡debería proporcionarle una buena base para comenzar!

JavaScript:

function validaterows(){
  var arrf01 = [], arrf02 = [];

  //fetch all the values from the source columns and put them in
  //a javascript array.
  $("input[name=f03]").each(function(){
    arrf01.push($v(this));
  });

  $("input[name=f04]").each(function(){
    arrf02.push($v(this));
  });

  //provide the constructed arrays to the on-demand process by using
  //the global f## arrays
  apex.server.process ( "MY_PROCESS", {
      f01: arrf01
    , f02: arrf02
  }, {
  , success: function( pData ) { 
      //pData should be an object, because jquery will have parsed the returned json-string
      apex.debug(pData);

      $.each(pData.validationArray, function(index, value){
        if ( value === 'INVALID' ) {
          // do something here when the result is invalid
          // maybe you want to color something red for example
          alert('The data at row '+index+' is not valid!');
        };
      });

      }
  } );
}

Proceso plsql bajo demanda:

DECLARE
  l_return VARCHAR2(4000);
BEGIN
  FOR i IN apex_application.g_f01.count
  LOOP
    -- remember: the f## arrays are varchar arrays. Important for comparisons.
    -- Also take into account that the values could NOT be numeric at all.
    -- you'll probably want to run each value through an is-number check or else 
    -- you'll run into ORA errors
    IF to_number(apex_application.g_f01(i)) > to_number(apex_application.g_f02(i))
    THEN
      l_return := l_return || ',"INVALID"';
    ELSE
      l_return := l_return || ',"VALID"';
    END IF;
  END LOOP;

  IF l_return IS NOT NULL
  THEN
    -- create a json string 
    -- holds an object with 1 property (validationArray) with the value being
    -- an array holding a value for each row submitted
    l_return := '{"validationArray":['||LTRIM(l_return, ',')||']}';
  END IF;

  -- write the output to the buffer
  htp.p(l_return);
END;