当前位置:网站首页>oracle apex ajax process + dy 校验
oracle apex ajax process + dy 校验
2022-07-02 06:24:00 【贤时间】
目前apex的后端校验,即用户输入后,点击提交才触发与后端服务器的校验,为了提升用户体验,可以把这一步前置,用js事件触发后端校验,以监测用户名是否重复为例。
演示环境为 apex 20.2
建立Ajax process
DECLARE
l_count NUMBER := 0;
BEGIN
--名称重复校验
IF :P5_1 IS NOT NULL THEN
SELECT COUNT(1)
INTO l_count
FROM 666 v
WHERE v.1 = :P5_1
AND ROWNUM = 1;
IF l_count > 0 THEN
htp.p('客户:' || :P5_1 || '已存在');
ELSE
htp.p('success');
END IF;
END IF;
--号重复校验
IF :P5_2 IS NOT NULL THEN
SELECT COUNT(1)
INTO l_count
FROM 666 v
WHERE v.2 = :P5_2
AND ROWNUM = 1;
IF l_count > 0 THEN
htp.p('已存号为:' || :P5_2|| '的客户!');
ELSE
htp.p('success');
END IF;
END IF;
END;
先在process直接建立proce,然后位置选择 ajax,注意pl/sql要有返回值,后面的js需要根据返回值进行判断。
注意:htp.p打印的后面会有一个空格或者制表符,js判断时需要考虑进行字符串去空格操作。或者这个地方直接打印json也可以(参加文末勘误)
在对应的表单页项上建立动态操作
js事件选择 改变(onchange) 或者 失去焦点 (onblur),真操作为执行js代码
apex.server.process('ajax_validate_customer_repeat',//这儿的名称为process的名称
{
pageItems: '#P5_PARTY_NAME'//注意带#号
}
,
{
dataType: 'text', success: function (data) {
if ( /*data*/ data.trim() != 'success') {
//用htp.p打印的后面带一个空格,不知道为啥,此处要注意,也可以用apex封装的api直接打印json
apex.message.clearErrors();
apex.message.showErrors([
{
type: "error",
location: ["page", "inline"],
pageItem: "P5_PARTY_NAME",
message: data,
unsafe: false
}/*, { type: "error", location: "page", message: data, unsafe: false }*/
]);
}
else
{
apex.message.clearErrors();
}
}
}
)
效果如下

后续改进
可以把重复校验的单独封装成一个js函数
function repeat_validate(page_item_name) {
apex.server.process('ajax_validate_customer_repeat',
{
pageItems: "#" + page_item_name
}
,
{
dataType: 'text', success: function (data) {
if ( /*data*/ data.trim() != 'success') {
apex.message.clearErrors();
apex.message.showErrors([
{
type: "error",
location: ["page", "inline"],
pageItem: page_item_name,
message: data,
unsafe: false
}
]);
}
else {
apex.message.clearErrors();
}
}
}
)
}
把上面这段js放到 页》JavaScript 》函数和全局变量声明 里面去。
然后在要验证的表单项上 高级》定制: οnchange=“repeat_validate(‘P5_XXX’);”
这样就实现了公用,不必再在此页项上定义动态操作了。
参考文档:
https://apex.oracle.com/pls/apex/germancommunities/apexcommunity/tipp/3341/index-en.html
https://www.foxinfotech.in/2020/04/oracle-apex-validation-without-submit-using-javascript-and-ajax-callback.html
勘误
htp.p 、htp.print 、htp.prn 三者是有区别的:
HTP.p is a shortcut (undocumented) to htp.print. HTP. Print adds a new line to the output.
HTP. PRN does not add a line break.
htp.p和htp.print 会在后面自动多一个/n 新行
hpt.prn不会多/n
https://docs.oracle.com/database/121/ARPLS/w_htp.htm#ARPLS70586
边栏推荐
- js创建一个自定义json数组
- [leetcode question brushing day 35] 1060 Missing element in ordered array, 1901 Find the peak element, 1380 Lucky number in matrix
- SQLI-LABS通关(less2-less5)
- Use of interrupt()
- JS create a custom JSON array
- DNS攻击详解
- php中通过集合collect的方法来实现把某个值插入到数组中指定的位置
- 搭建frp进行内网穿透
- js把一个数组分割成每三个一组
- oracle EBS标准表的后缀解释说明
猜你喜欢
随机推荐
js创建一个自定义json数组
AWD learning
SQLI-LABS通关(less6-less14)
2021-07-17c /cad secondary development creation circle (5)
Queue (linear structure)
php中删除指定文件夹下的内容
CAD secondary development object
In depth study of JVM bottom layer (V): class loading mechanism
SQL injection closure judgment
[daily question] - Huawei machine test 01
php中的数字金额转换大写数字
2021-07-05c /cad secondary development create arc (4)
Sqli-labs customs clearance (less15-less17)
Eggjs -typeorm treeenity practice
Sqli labs customs clearance summary-page1
Win10: add or delete boot items, and add user-defined boot files to boot items
Deployment API_ automation_ Problems encountered during test
2021-07-17C#/CAD二次开发创建圆(5)
Implement strstr() II
sqli-labs通關匯總-page2









