问题
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.
回答1:
Yes, you can create server side validation by using Dynamic Action
and JavaScript function apex.server.process
.
A basic example to demonstrate-
- Create a page item e.g. P4_NAME in your page
- Create a page process and select the execution point as "AJAX CALLBACK".
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;
- 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.
- Create a true action and select "execute JavaScript Code".
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);
}
}
)
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.
You can customize your JS code further to display error messages in more fancy way instead of showing alert.
来源:https://stackoverflow.com/questions/45312328/how-can-i-create-oracle-apex-server-side-live-validation-without-need-to-submit