2017-07-25 78 views
1

我創建的形式爲客戶頁面,我需要做驗證客戶的名稱,如我怎樣才能無需提交

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. 
+0

請不要打擾#4(「防止客戶端導航」),它會導致用戶的糟糕的UI體驗。 –

回答

3

是的,你可以通過使用Dynamic Action創建服務器端驗證創建的Oracle APEX服務器端實時驗證和JavaScript功能apex.server.process

一個基本的例子,以demonstrate-

  • 例如創建頁面項P4_NAME
  • 創建頁面進程並選擇執行點爲「AJAX CALLBACK」。 enter image description here

在下面的代碼,我檢查P4_ITEM值,你可以寫你自己的邏輯來驗證。

BEGIN 
    IF :P4_NAME = 'HIMANSHU' 
    THEN 
     HTP.prn ('SUCCESS'); 
    ELSE 
     HTP.prn ('ERROR'); 
    END IF; 
END; 
  • 現在創建一個新的動態動作和選擇事件爲「失焦」,選擇類型爲「項目(S)」,並在項目(S)選擇項目名稱。

enter image description here

  • 創建一個真正的行動,並選擇 「執行JavaScript代碼」。

在代碼段,實現apex.server.process像如下─

apex.server.process('validate_name', 
{ 
    pageItems : '#P4_NAME' 
} 
, 
{ 
    dataType : 'text', success : function(data) 
    { 
     if(data != 'SUCCESS')alert(data); 
    } 
} 
) 

第一個參數是頁面進程名(validate_name),其前面我們已經建立,第二要提交到過程中的數據和第三是選項。 有關apex.server.process的更多詳細信息

完成。刷新頁面並檢查。驗證失敗後,您將收到警報。

您可以進一步自定義您的JS代碼,以更加奇特的方式顯示錯誤消息,而不是顯示警報。

+0

非常感謝,非常有幫助 –

+0

歡迎您!不要忘記標記這個答案有幫助。 – Himanshujaggi