我如何创建oracle apex服务器端实时验证而无需提交页面 [英] How can I create oracle apex server side live validation without need to submit page
问题描述
我为客户创建了表单,我需要像
I created form for customers, I need to do validate customer name like
1 - type the new name into item P1_CUST_NAME.
2 - after leaving this item go to database and check if this name already exist or not.
3 - display alert or message for the client.
4 - prevent the client from navigating a way from this item until he enter valid data.
推荐答案
是的,您可以使用Dynamic Action
和JavaScript函数apex.server.process
创建服务器端验证.
Yes, you can create server side validation by using Dynamic Action
and JavaScript function apex.server.process
.
一个基本的例子来演示-
A basic example to demonstrate-
- 创建页面项目,例如您页面中的P4_NAME
- 创建页面处理并将执行点选择为"AJAX 打回来".
- Create a page item e.g. P4_NAME in your page
- Create a page process and select the execution point as "AJAX CALLBACK".
在下面的代码中,我正在检查P4_ITEM值,您可以编写自己的逻辑进行验证.
In below code I am checking the P4_ITEM value, you can write your own logic to validate.
BEGIN
IF :P4_NAME = 'HIMANSHU'
THEN
HTP.prn ('SUCCESS');
ELSE
HTP.prn ('ERROR');
END IF;
END;
- 现在创建一个新的动态操作,然后将事件选择为"LOSE FOCUS",将选择类型选择为项目",并在项目中).选择商品名称.
- Now create a new dynamic action and select the Event as "LOSE FOCUS", Selection Type as "Item(s)" and in Item(s) select the item name.
- 创建一个真实的动作,然后选择执行JavaScript代码".
在代码部分中,像下面一样实现apex.server.process
-
In code section, implement apex.server.process
like below-
apex.server.process('validate_name',
{
pageItems : '#P4_NAME'
}
,
{
dataType : 'text', success : function(data)
{
if(data != 'SUCCESS')alert(data);
}
}
)
第一个参数是我们之前创建的页面流程名称(validate_name),第二个是您要提交给流程的数据,第三个是选项. 有关 apex.server.process
The first argument is the page process name(validate_name) which we have create earlier, second the data you want to submit to the process and third is options. For more details on apex.server.process
完成了.刷新页面并检查.验证失败时,您会收到警报.
It is done. Refresh your page and check. On validation failure you will get an alert.
您可以进一步自定义JS代码,以更精致的方式显示错误消息,而不是显示警报.
You can customize your JS code further to display error messages in more fancy way instead of showing alert.
这篇关于我如何创建oracle apex服务器端实时验证而无需提交页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!