Skip to main content

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:

nametypedescription
formValObjectForm value
originalFormValObjectThe value of the form before saving
ancestorsString[]Parent item ids
createdAtStringCreation time
userUserCreator 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:

nametyperequireddescription
ancestorOptionObjecttrueOptions collection
ancestorOption.ancestorsString[]trueParent item ids
ancestorOption.statusIdStringtrueStatus 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:

nametyperequireddescription
userIdStringtrueUser 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:

nametyperequireddescription
itemIdStringtrueItem 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:

nametyperequireddescription
workspaceNameStringtrueWorkspace 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:

nametyperequireddescription
methodStringtrueGET/POST/PUT/PATCH
urlStringtrueThe requested url
dataObjectfalseThe requested data

EXAMPLE:

const result = await apis.requestCoreApi('POST', '/parse/api/search/structure', data);
console.log(result)