当前位置:网站首页>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
边栏推荐
- Differences between ts and JS
- php中计算树状结构数据中的合计
- PXC high availability cluster summary
- Code execution sequence with and without resolve in promise
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- Sqli labs customs clearance summary-page2
- sqli-labs通关汇总-page1
- js把一个数组分割成每三个一组
- SQL injection closure judgment
- 在php的开发环境中如何调取WebService?
猜你喜欢
随机推荐
PIP install
JS divides an array into groups of three
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
Browser scrolling for more implementations
JS countdown case
Tool grass welfare post
JS judge whether the object is empty
Sqli-labs customs clearance (less18-less20)
工具种草福利帖
php中计算两个日期之前相差多少天、月、年
sqli-labs通关汇总-page4
Huawei mindspire open source internship machine test questions
Usage of map and foreach in JS
Fe - wechat applet - Bluetooth ble development research and use
Review of reflection topics
Go common compilation fails
Build learning tensorflow
蚂蚁集团g6初探
Anti shake and throttling of JS
pm2简单使用和守护进程