Form Validation
Introduction
What is form validation
Form validation refers to the validation of form fields.
Form validation script
Form verification scripts are divided into verification scripts, verification scripts before saving, and verification scripts after saving, which can be configured in the form settings of the interface configuration:
Form validation script take effect
Real-time verification when editing item:
Validate when saving item:
Script parameters
The following parameters can be used directly in the script:
name | type | description |
---|---|---|
formVal | Object | Form value |
originalFormVal | Object | The value of the form before saving |
ancestors | String[] | Parent item ids |
createdAt | String | Creation time |
user | User | Creator information |
Api reference
judgeAncestorsStatus
During form validation, determine whether the parent card status of the current child card is after the given status
API PARAMETERS:
name | type | required | description |
---|---|---|---|
ancestorOption | Object | true | Options collection |
ancestorOption.ancestors | String[] | true | Parent item ids |
ancestorOption.statusId | String | true | Status id |
RETURN:
JudgeResult - The result of judgment
interface JudgeResult {
resultFlag: boolean
}
EXAMPLE:
const ancestorOption = {
ancestors,
statusId: '1',
}
const {resultFlag} = await apis.judgeAncestorsStatus(ancestorOption);
if(resultFlag) {
throw new Error('This is an error message')
}
getRolesByUserId
Get user roles
API PARAMETERS:
name | type | required | description |
---|---|---|---|
userId | String | true | User id |
RETURN:
Role[] - The user system roles
EXAMPLE:
const roles = await apis.getRolesByUserId(user.objectId);
const notMatch = !roles.find(role => role.name === 'QA' );
if(notMatch){
throw new Error('This is an error message')
}
getItem
Get item data
API PARAMETERS:
name | type | required | description |
---|---|---|---|
itemId | String | true | Item id |
RETURN:
ItemJSONObject - Item data
EXAMPLE:
const data = await apis.getItem(itemId);
if(data.name !== 'item name'){
throw new Error('This is an error message')
}
getWorkspaceNames
Get all workspace names
RETURN:
string[] - Workspace names
EXAMPLE:
const workspaceNames = await apis.getWorkspaceNames();
if(workspaceNames.length<=0) {
throw new Error('This is an error message')
}
checkWorkspaceName
Check if workspace name exists
API PARAMETERS:
name | type | required | description |
---|---|---|---|
workspaceName | String | true | Workspace name |
RETURN:
CheckResult - The result of check
interface {
isExist: boolean;
}
EXAMPLE:
const {isExist} = await apis.checkWorkspaceName(formVal.workspace.name);
if(isExist){
throw new Error('Workspace name already exists')
}
requestCoreApi
Provide the ability to directly call the core interface externally, and expose the GET/POST/PUT/PATCH methods
API PARAMETERS:
name | type | required | description |
---|---|---|---|
method | String | true | GET/POST/PUT/PATCH |
url | String | true | The requested url |
data | Object | false | The requested data |
EXAMPLE:
const result = await apis.requestCoreApi('POST', '/parse/api/search/structure', data);
console.log(result)