Before You Begin
The following APIs require a basic knowledge ofJavaScript. You should be familiar with common data types, declaring and using variables and functions, and know how to avoid a few common JavaScript pitfalls.
Take this.state, this.setState, and this.$(), which appear frequently in the APIs below, as an example. When this appears at the top level of an event handler function, it points to the correct execution context, so you can read from and write to Data Sources and read values from other form fields without issue:
this appears inside a nested function, make sure it still points to the right context:
JavaScript getting-started guides:
Global Variable APIs
YiDA’s design pattern is largely inspired by React. It provides global variables for page-level state management, along with APIs that trigger a page re-render (see the global variable documentation for details).this.state.xxx
Get the value of a global variable (identical to the React API).xxx is typically the variable name of a page-level Data Source.
Example:
this.setState()
Set the value of a global variable and trigger a page re-render (largely identical to the React API). Note: Do not modify a variable usingthis.state.a = b. Compatibility is not guaranteed in future updates, and such code may stop working.
Example:
Remote Data APIs
YiDA supports configuring remote Data Sources and provides APIs that trigger remote Data Source calls from JS (see the remote API documentation for details).this.dataSourceMap.xxx.load()
Manually call the specified remote API.xxx is the Data Source name configured in the Data Source panel. You can also pass request parameters; the parameters passed here are merged with the ones configured in the Data Source before the request is sent. load returns a Promise.
Example:
this.reloadDataSource()
Reload all remote APIs whose auto-load option is set to true. This method also returns a Promise. Example:JS Invocation APIs
YiDA provides the action panel for authoring JS code. Functions in the action panel can be bound to variables or actions, and can also invoke each other.this.methodName()
YiDA provides a way to invoke other JS functions in the action panel. Callthis.xxx(), where xxx is the name of the other function.
Example:
Utility APIs
YiDA provides many built-in utility functions that help you implement common features more easily.this.utils.dialog()
Open a dialog. The effect is shown below. The user must close it manually. YiDA uses Fusion components under the hood, so you can configure any property supported by the Dialog component. Documentation. The commonly used properties are listed below:
Example:
this.utils.formatter()
A common formatter function for formatting dates, currency, phone numbers, and more. Example:this.utils.getDateTimeRange(when, type)
Get the start and end timestamps of the current or a specified date range. Bothwhen and type are optional. By default it returns the start and end of the current day; you can also specify the date and range type.
Example:
this.utils.getLocale()
Get the current page locale. Example:this.utils.getLoginUserId()
Get the ID of the signed-in user. Example:this.utils.getLoginUserName()
Get the name of the signed-in user. Example:this.utils.isMobile()
Check whether the current environment is a mobile device. Example:this.utils.isSubmissionPage()
Check whether the current page is a data-submission page. Example:this.utils.isViewPage()
Check whether the current page is a data-view page. Example:this.utils.loadScript()
Dynamically load a remote script. Example:this.utils.openPage()
Open a new page. In the DingTalk environment, the DingTalk API is used to open the new page for a smoother experience. Example:this.utils.previewImage()
Preview an Image. This API provides a lightweight Image preview experience, as shown below: Example:this.utils.toast()
Show a lightweight message. Compared with the Dialog, a toast is more lightweight and disappears automatically after a short delay, as shown below: Parameters:
Example:
Routing APIs
YiDA provides APIs for retrieving routing information and navigating between pages. These APIs are built on top of react-router, so the navigation APIs are largely consistent with the react-router APIs. YiDA also offers a few additional routing extensions.this.utils.router.push()
Navigate to a new page and push the entry onto the routing stack, so the user can go back via the browser’s Back button. The parameters ofpush are described below:
Example:
this.utils.router.replace()
Replace the current page. Unlikerouter.push, this API replaces the current page instead of pushing a new one, so it cannot be reversed by the browser’s Back button. Equivalent to:
this.utils.router.getQuery()
Get URL parameters of the current page. When akey is provided, return the corresponding value; otherwise return all URL parameters. Parameters of getQuery:
Example:
this.utils.router.stringifyQuery()
Serialize URL parameters, converting an object into a URL query string. Example:Common Component APIs
Before diving into component-specific APIs, a few concepts should be introduced up front:- Component unique identifier (fieldId) — YiDA assigns a unique identifier to every Component to distinguish Component instances. The identifier can be viewed in the Component property panel.
- Component property (prop) — In YiDA, every Component exposes properties to enable different behaviors (similar to React props). Hover a control in the Component property panel to see the corresponding property name.
this.$(fieldId).get(prop)
Look up a Component by fieldId and read one of its property values.fieldId is the Component identifier and prop is the Component property name.
Note: Do not read a property value using this.$(fieldId).xxx. Compatibility is not guaranteed in future updates, and such code may stop working.
Example:
this.$(fieldId).set(prop, value)
Look up a Component by fieldId and set one of its property values.fieldId is the Component identifier, prop is the property name, and value is the value to set.
Note: Do not set a property value using this.$(fieldId).xxx = xxx. Compatibility is not guaranteed in future updates, and such code may stop working.
Example:
Form Component APIs
Form components are the most important type of Component on the YiDA platform. They are typically used to collect Data — for example, text fields, single-choice, Multiselect, and dropdown selects. This section covers the APIs related to form components.this.$(fieldId)
Get a Component instance, wherefieldId is the component unique identifier. Before calling a Component API, obtain the Component instance via this.$(fieldId) first.
Note: Do not access undocumented APIs or properties through this.$(fieldId).xxx. Anything not documented is a private internal implementation. Compatibility is not guaranteed in future updates, and such code may stop working.
this.$(fieldId).getValue()
Get the input value of the specified form component. Example:this.$(fieldId).setValue()
Set the input value of the specified form component. Parameters ofsetValue:
this.$(fieldId).reset()
Reset the input value of the specified form component. Parameters ofreset:
this.$(fieldId).getBehavior()
Get the current state of the specified form component. Possible states include:- NORMAL — normal state (editable).
- READONLY — read-only state.
- DISABLED — disabled state.
- HIDDEN — hidden state.
this.$(fieldId).setBehavior()
Set the state of the specified form component. Available states are described in thegetBehavior section.
Example:
this.$(fieldId).resetBehavior()
Reset the state of the specified form component. Example:this.$(fieldId).validate()
Run validation once on the specified form component. Parameters ofvalidate:
this.$(fieldId).disableValid()
Disable validation on the form component. Example:this.$(fieldId).enableValid()
Enable validation on the form component. Parameters ofenableValid:
this.$(fieldId).setValidation()
Set the validation rules on the form component. Parameters ofsetValidation:
Example:
this.$(fieldId).resetValidation()
Reset the validation rules on the form component. Use it aftersetValidation to restore the previous rules. Parameters of resetValidation: