且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用DatePicker Oracle Apex上的Dynamic Action比较日期

更新时间:2022-10-16 23:08:04

As @ScottWe提到:你试图在HTML / javascript中应用PLSQL逻辑。 'When - Condition'在运行时被评估,因此你不能在那里使用PLSQL。
日期算术在JavaScript中有点恼人,所以如果你不熟悉,这里是一种方式可以执行你的支票(即是明天的输入日期)。



从我的线索:

Javascript中的日期差异(忽略一天中的时间)

JavaScript如何以dd-mm-yy格式获取明天日期



将这个函数添加到页面的JavaScript部分,以获取全局变量和函数:

  function isTomorrow(pDateItem){
function getTomorrow(){
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate()+ 1);
明天回来
};

函数cutTime(pDate){
返回新日期(pDate.getFullYear(),pDate.getMonth(),pDate.getDate());
};

//检查pDateItem是否导致选择
//检查是否是datepicker
//检查是否已选择日期
if($( pDateItem).length
&&$(pDateItem).data(datepicker)
&& $(pDateItem).datepicker(getDate)!== null

{
var tomorrow = getTomorrow();
var check = $(pDateItem).datepicker(getDate);
var one = cutTime(check);
var two = cutTime(tomorrow);

return one.getDate()=== two.getDate();
};
返回false;
}

然后在动态动作When条件下,使用一个javascript表达式代码:

  isTomorrow(this.triggeringElement)

然后,当日期设置为明天时,相应的True Actions才会触发。


I have a date picker where the user simply chooses a date then a Dynamic Action is suppose to send an alert if the user clicks tomorrow(sysdate+1).

The Datepicker term is the simple layout.

The Dynamic Action-->

Name: Valid Date

Event: Change

Selection type: Item(s)

Item(s): datepicker_name

Condition: equal to

Value: sysdate+1

When I run the program and click any day on the calendar, no alert comes up. I thought the problem was the format. The Dynamic Action sees the date as "DD/MM/YYYY" while the Datepickers output is "DD-Mon-YY" so it could not compare them. Apples and Oranges. But I played around with the format to make it all the same but still no progress.

Thanks again for your time and help!

As @ScottWe mentions: you're trying to apply PLSQL logic in HTML/javascript. The 'When - Condition' is evaluated at runtime and thus you can't use PLSQL there. The date arithmetic is a bit annoying in javascript though, so if you're a unfamiliar with it, here is a way you can perform your check (which is, is the entered date tomorrow or not).

Taking my clues from these:
Date difference in Javascript (ignoring time of day)
JavaScript how to get tomorrows date in format dd-mm-yy

Add this function to the page's javascript section for global variables and functions:

function isTomorrow(pDateItem){  
  function getTomorrow(){ 
    var tomorrow = new Date();
    tomorrow.setDate(tomorrow.getDate() + 1);
    return tomorrow;
  };

  function cutTime(pDate){
    return new Date(pDate.getFullYear(), pDate.getMonth(), pDate.getDate());
  };

  // check if pDateItem leads to a selection
  // check if it is a datepicker
  // check if a date has been selected
  if ( $(pDateItem).length 
       && $(pDateItem).data("datepicker")
       && $(pDateItem).datepicker("getDate") !== null 
     ) 
  {        
    var tomorrow = getTomorrow();
    var check = $(pDateItem).datepicker("getDate");
    var one = cutTime(check);
    var two = cutTime(tomorrow);

    return one.getDate() === two.getDate();
  };
  return false;
}

Then in your Dynamic action 'When' condition, use a javascript expression with this code:

isTomorrow(this.triggeringElement)

Then the corresponding True Actions will only fire when the date is set to tomorrow.