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!

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
419 views