✏️ Explanatory Question
The validate() method is a standard method on the field of the form data source. This method is called when a value is entered in a specific field, and it's overridden if extra field validation is needed.
Example
You have a custom form with a table named TrainingMaster. The table has a field named Participants, where entering a number higher than 20 isn't allowed.
The coding pattern can be as follows:
[DataSource]
class TrainingMaster
{
[DataField]
class Participants
{
public boolean validate()
{
boolean ret;
ret = super() && (TrainingMaster.Participants <= 20);
return ret;
}
}
}
Make sure that you offer a reason for errors that are thrown, as shown in the following code example:
[DataSource]
class TrainingMaster
{
[DataField]
class Participants
{
public boolean validate()
{
boolean ret;
if (TrainingMaster.Participants > 20)
{
throw error("Maximum 20 participants");
return false;
}
ret = super();
return ret;
}
}
}