The Base class serves as base for all field validators.
More...
|
Boolean | checkDelete (Object aRecord) |
| Checks if the record data is valid for delete. More...
|
|
Boolean | checkInsert (Object aRecord) |
| Checks if the record data is valid for insert. More...
|
|
Boolean | checkUpdate (Object aRecord) |
| Checks if the record data is valid for update. More...
|
|
|
| Base (Datastore aDatastore, String aTable) |
|
Boolean | checkLength (Object aRecord, String aColumn) |
| Checks if the value length exceeds the maximum column length. More...
|
|
Boolean | checkMask (Object aRecord, String aColumn) |
| Checks if the column value is valid for the mask. More...
|
|
Boolean | checkNotNull (Object aRecord, String aColumn) |
| Checks if the given column is not null. More...
|
|
Boolean | checkReference (Object aRecord, String aColumn, String aRefTable) |
| Checks if the given column is either null, or references the primary key of an existing row in aRefTable. More...
|
|
Boolean | checkUnique (Object aRecord, String aColumn) |
| Checks if the column value is unique within the whole table. More...
|
|
Boolean | checkUnique2 (Object aRecord, String aColumn1, String aColumn2) |
| Checks if the combination of 2 columns is unique. More...
|
|
Boolean | checkUniqueNotDeleted (Object aRecord, String aColumn) |
| Checks if the column value is unique within the whole table, excluding records with "deleted" status from the check ('d' in column c_status). More...
|
|
Boolean | checkUniqueOrNull (Object aRecord, String aColumn) |
| Checks if the column value is either NULL or unique within the whole table. More...
|
|
void | clear () |
| Clears the status by setting lastStatus = bps.FieldValidator.StatusOK and lastColumn = ''. More...
|
|
The Base class serves as base for all field validators.
The validator needs to be implemented in a distinct js file and placed somewhere in the file system, typically in the BPS program folder under scripts/validators. The file must be registered in the global system settings in folder Validators as key / value pair, where the key is the table name and the value is the absolute or relative script file path/name.
Below is a complete sample validator implementation for the t_countries table. (Check out scripts/validators/default/* for more samples)
function BpsFieldValidator(aDatastore)
{
}
BpsFieldValidator.prototype.
checkUpdate =
function(aRecord)
{
}
void importExtension(String aExtensionName)
Imports the named extension into the script engine.
This class implements the BPS table field validator.
Definition: bps.FieldValidator.js:40
@ StatusOK
All checks passed ok.
Definition: bps.FieldValidator.js:47
The Base class serves as base for all field validators.
Definition: bps.validator.js:51
Boolean checkMask(Object aRecord, String aColumn)
Checks if the column value is valid for the mask.
String lastColumn
Column on which an error occurred, set by the check() execution.
Definition: bps.validator.js:58
Status lastStatus
The status set by the check() execution.
Definition: bps.validator.js:58
Boolean checkUnique(Object aRecord, String aColumn)
Checks if the column value is unique within the whole table.
Boolean checkUpdate(Object aRecord)
Checks if the record data is valid for update.
The bps.validator extension is a namespace holding the base class for field validators.
Definition: bps.validator.js:7
The bps extension is a namespace assembling general BPS properties and functions.
Definition: bps.AsyncIO.js:1
◆ Base()
- Parameters
-
aDatastore | Datastore object in connected state. |
aTable | Name of the main table the validator operates on. |
◆ checkDelete()
Boolean bps::validator::Base::checkDelete |
( |
Object |
aRecord | ) |
|
Checks if the record data is valid for delete.
Stops on first fail and sets the values of properties lastStatus and lastColumn.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
- Returns
- True if all column checks passed, false otherwise.
◆ checkInsert()
Boolean bps::validator::Base::checkInsert |
( |
Object |
aRecord | ) |
|
Checks if the record data is valid for insert.
Stops on first fail and sets the values of properties lastStatus and lastColumn.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
- Returns
- True if all column checks passed, false otherwise.
◆ checkLength()
Boolean bps::validator::Base::checkLength |
( |
Object |
aRecord, |
|
|
String |
aColumn |
|
) |
| |
|
protected |
Checks if the value length exceeds the maximum column length.
Sets lastStatus and lastColumn in case the check fails, and returns false.
The check is only done when aRecord contains aColumn as property, otherwise it will just return true.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
- Returns
- True if ok, false otherwise.
◆ checkMask()
Boolean bps::validator::Base::checkMask |
( |
Object |
aRecord, |
|
|
String |
aColumn |
|
) |
| |
|
protected |
Checks if the column value is valid for the mask.
Sets lastStatus and lastColumn in case the check fails, and returns false.
The check is only done when the mask for aColumn is found and aRecord contains aColumn as property, otherwise it will just return true.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
- Returns
- True if ok, false otherwise.
◆ checkNotNull()
Boolean bps::validator::Base::checkNotNull |
( |
Object |
aRecord, |
|
|
String |
aColumn |
|
) |
| |
|
protected |
Checks if the given column is not null.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
- Returns
- True if ok, false otherwise.
◆ checkReference()
Boolean bps::validator::Base::checkReference |
( |
Object |
aRecord, |
|
|
String |
aColumn, |
|
|
String |
aRefTable |
|
) |
| |
|
protected |
Checks if the given column is either null, or references the primary key of an existing row in aRefTable.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
aRefTable | Name of the referenced table. |
- Returns
- True if ok, false otherwise.
◆ checkUnique()
Boolean bps::validator::Base::checkUnique |
( |
Object |
aRecord, |
|
|
String |
aColumn |
|
) |
| |
|
protected |
Checks if the column value is unique within the whole table.
Sets lastStatus and lastColumn in case the check fails, and returns false. The check is only done when aRecord contains c_key and aColumn as properties, otherwise it will return true.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
- Returns
- True if ok, false otherwise.
◆ checkUnique2()
Boolean bps::validator::Base::checkUnique2 |
( |
Object |
aRecord, |
|
|
String |
aColumn1, |
|
|
String |
aColumn2 |
|
) |
| |
|
protected |
Checks if the combination of 2 columns is unique.
Sets lastStatus and lastColumn in case the check fails, and returns false.
The check is only done when aRecord contains c_key
, aColumn1 and aColumn2 as properties, otherwise it will return true.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn1 | Name of the first column. |
aColumn2 | Name of the second column. |
- Returns
- True if ok, false otherwise.
◆ checkUniqueNotDeleted()
Boolean bps::validator::Base::checkUniqueNotDeleted |
( |
Object |
aRecord, |
|
|
String |
aColumn |
|
) |
| |
|
protected |
Checks if the column value is unique within the whole table, excluding records with "deleted" status from the check ('d' in column c_status).
Used to check the column c_id in tables t_articles and t_partners for example. Sets lastStatus and lastColumn in case the check fails, and returns false.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
- Returns
- True if ok, false otherwise.
◆ checkUniqueOrNull()
Boolean bps::validator::Base::checkUniqueOrNull |
( |
Object |
aRecord, |
|
|
String |
aColumn |
|
) |
| |
|
protected |
Checks if the column value is either NULL or unique within the whole table.
Sets lastStatus and lastColumn in case the check fails, and returns false.
The check is only done when aRecord contains c_key and aColumn as properties, otherwise it will return true.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
aColumn | Name of the column value to check. |
- Returns
- True if ok, false otherwise.
◆ checkUpdate()
Boolean bps::validator::Base::checkUpdate |
( |
Object |
aRecord | ) |
|
Checks if the record data is valid for update.
Stops on first fail and sets the values of properties lastStatus and lastColumn.
- Parameters
-
aRecord | The record to check, where the properties hold the column values. |
- Returns
- True if all column checks passed, false otherwise.
◆ clear()
void bps::validator::Base::clear |
( |
| ) |
|
|
protected |
◆ datastore
[protected] Datastore object used by the validator.
To be set via constructor only, dont change after.
◆ lastColumn
String bps::validator::Base::lastColumn |
|
readwrite |
Column on which an error occurred, set by the check() execution.
Empty in case all checks passed.
◆ lastStatus
Status bps::validator::Base::lastStatus |
|
readwrite |
◆ masks
Object bps::validator::Base::masks |
|
readwrite |
[protected] Mask cache used by checkMask().
Properties are the already fetched masks for columns previously processed. For columns where no mask was found, an empty string is stored as mask.
◆ table
String bps::validator::Base::table |
|
read |
[protected] The main table handled by the validator.
To be set via constructor only, dont change after.
The documentation for this class was generated from the following file: