Skip to main content

Custom validations

Sometimes there is a need to create a custom action validation (ex. move is enabled but change of the resource could not be possible). In order to create such functions and add apex success or error messages tere are predefined validationes per action (click, move, resize). Such validations can be added in the Gantt "JavaScript Initialization Code".

Resize Task

Before executing resize action, script check for an internal "validateResize" function.

function (pOptions) {

pOptions.methods = {
validateResize : function(task, resizeData) {
console.log("Validate RESIZE on", task, resizeData);
apex.message.clearErrors();
if (new Date(task.finish) > new Date()) {
return true;
}
else {
apex.message.showErrors([
{
type: "error",
location: [ "page" ],
message: `Task "${task.name }" ended resize is disabled!`,
unsafe: false
}
]);
return false;
}
return true;
}
};

return pOptions;
}

Move Task

Before executing move (drag and drop) action, script check for an internal "validateMove" function.

function (pOptions) {

pOptions.methods = {
validateMove : function(task, moveData) {
console.log("Validate MOVE on", task, moveData);
apex.message.clearErrors();
if (moveData.detail.rowContext.rowData.id != task.resourceId) {
apex.message.showErrors([
{
type: "error",
location: [ "page" ],
message: `Move of the task "${task.name }" to the different resource is disabled!`,
unsafe: false
}
]);
return false;
}
else if (new Date(task.finish) < new Date()) {
apex.message.showErrors([
{
type: "error",
location: [ "page" ],
message: `Task "${task.name }" ended move is disabled!`,
unsafe: false
}
]);
return false;

} else {
return true;
}

}
};

return pOptions;
}

Click on task

Before executing click action, script check for an internal "validateClick" function.

function (pOptions) {

pOptions.methods = {
validateClick : function(task) {
console.log("Validate CLICK on", task);
apex.message.clearErrors();
if (task.resource == "Load Software") {
return true;
}
else {
apex.message.showErrors([
{
type: "error",
location: [ "page" ],
message: `Click on Resource "${task.resource }" is disabled!`,
unsafe: false
}
]);
return false;
}
}
};

return pOptions;
}