gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:39:40 24 4
gpt4 key购买 nike

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

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

我现在有一个可以有 1 到 n 行的表格形式,但是当用户按下“应用”按钮时,我需要根据上面的线程执行相同类型的验证,即:

一组示例行可能是这样的:

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) 调用按下“应用”按钮时,我需要使用以上四列(无复选框)遍历每一行在这里使用,只需选择列表,选择列值),调用我的ajax 进程检查是否:

(Col2 > Col4) for all rows 

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

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

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

最佳答案

我将如何尝试解决它。请注意,这并不涵盖所有(任何?)可能性或大量错误处理。你必须自己详细说明一下。例如,我将输入用于选择器,您需要“选择”。数组可能不匹配。您可能需要一个完全不同的选择器,例如 td[headers]。也许您的返回对象需要保存其他或更多值。您的 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;

关于javascript - 如何使用 Ajax 在 Oracle APEX 表格表单上逐行执行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com