How can I create oracle apex server side live validation without need to submit page

拈花ヽ惹草 提交于 2020-01-05 05:57:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!