首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Ajax在Oracle APEX表格表单上执行逐行验证?

如何使用Ajax在Oracle APEX表格表单上执行逐行验证?
EN

Stack Overflow用户
提问于 2014-02-05 14:51:19
回答 1查看 8.2K关注 0票数 3

使用与我基于此线程执行的相同的验证/处理:

Calling an Oracle Function via Ajax for on the spot Validation Purposes in Oracle APEX v4.2.2

我现在有一个可以有1到n行的表格表单,但是当用户按下"Apply“按钮时,我需要基于上面的线程执行相同类型的验证,即:

示例行集可能如下所示:

Col1    Col2    Col3    Col4
----------------------------
A       10      20      30
B       5       8       9
C       92      88      12
D       1       2       44
E       95      77      88

基于上面的场景,当用户通过动态操作/ ajax (apex.server.process)调用按下"Apply“按钮时,我需要使用上面的四列(这里没有使用复选框,只选择列表,以选择列值)遍历每一行,调用我的ajax流程来检查是否:

(Col2 > Col4) for all rows 

如果是,则通过javascript向用户返回警告消息,指示发现了数据的问题(即,来自apex.server.process的无效响应)。

在将记录提交到数据库之前,我基本上需要检查所有行的验证。

理想情况下,我希望通过DA/Ajax/jQuery解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2014-02-05 15:46:40

我会如何尝试去解决它。请注意,这并没有涵盖所有内容(有吗?)可能发生的错误或大量的错误处理。你得自己详细解释一下。例如,我为选择器使用了输入,你需要"select“。数组可能不匹配。您可能需要一个完全不同的选择器,比如by tdheaders。也许您的返回对象需要保存其他或更多的值。你的js可能需要更多的扩展。

无论如何,它应该为你提供一个良好的起点!

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!');
        };
      });

      }
  } );
}

按需plsql进程:

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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21570464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档