16.8.2.5.4.4 Invalidating Required Queried-Null Titles

Invalidate required grid cells with no value when queried so users must enter titles before posting photos.

When the interactive grid queries the EBA_DEMO_WOODSHR_TEMP_PHOTOS view, the image titles are initially null. While the TITLE column's Value Required switch is enabled, by default clicking the (Post Photos) button does not raise an error as you might expect. The grid validates data that the user has changed or created in the page, and considers queried data to already be valid. So, if the user does not type into the queried-null TITLE column cells and clicks to proceed with posting her images, no validation occurs.

The solution is to proactively invalidate any empty TITLE cells when the grid loads its data. Start by assigning an HTML DOM ID of addPhotoTitles to the grid region. Then, use a dynamic action event handler on the Selection Changed [Interactive Grid] event to run the following small bit of JavaScript. It gets the model object for the grid using its static ID. The grid's model holds the in-memory rows of data being edited in the browser.

The code uses a forEach to run the inline function on each model row. If any row has a null or empty TITLE column value, it "dirties" that row by setting its value to a space and then back to what it was before. By using this approach, the user sees the expected validation errors if they leave the required image titles blank.

// Run by Selection Changed [Interactive Grid]
// dynamic action event handler
const model = apex.region("addPhotoTitles")
                  .widget()
                  .interactiveGrid("getViews","grid")
                  .model;

model.forEach(function (rec) {
    const titleVal = model.getValue(rec, "TITLE");
    if (titleVal === null || titleVal === "") {
        // Dirty the TITLE so IG will validate on Save
        model.setValue(rec, "TITLE", " ", true);
        model.setValue(rec, "TITLE", titleVal, true);
    }
});