Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Date picker validation in IG

Staš ČarfJan 7 2025

Trying here again. I am still working on an application for which I need to validate the two date picker columns I have in my interactive grid (arrival and departure). I have changed the code a bit and am currently stuck at a point where I get the records and an error message get's displayed, but even if the departure date is before the arrival date (that's what I'm validating) I can still save the incorrect date without a problem when that shouldn't be the case. Below is the code I'm using in a dynamic action set to Save[Interactive Grid].

var grid = apex.region("IGSID").widget().interactiveGrid("getViews", "grid");
var model = grid.model;
var view = grid.view$.grid("getSelectedRecords");
var isValid = true;

if (view.length > 0) {
    var record = view[0];
    console.log("Record: ", record);
    
    var arrivalDate = record[5]; 
    var departureDate = record[6]; 

    console.log("Arrival Date: ", arrivalDate);
    console.log("Departure Date: ", departureDate);

    if (new Date(departureDate.split('.').reverse().join('-')) <= new Date(arrivalDate.split('.').reverse().join('-'))) {
        isValid = false;
        apex.message.showErrors([
            {
                type: "error",
                location: "page",
                message: "Departure date must be after arrival date.",
                unsafe: false
            }
        ]);
        model.setValidity(record, "departure_date", false);
    }
}
if (!isValid) {
    apex.event.gCancelFlag = true;
    return false;
}
return isValid;
Comments
Post Details
Added on Jan 7 2025
5 comments
95 views