Skip to content

Methods (methods)

Designers can use Vue's methods approach in scripts to execute personalized business logic. For example: after listening to data changes, calculate page data or call automations through methods.

Built-in Variables

Form data (form)

For example, if the designed form contains a single-line text field with the identifier (name)

javascript
// Get form field (name) data
console.log(this.form.name);
// Set form field (name) data
this.form.name = "Zhang San";

informat

The globally available informat object. After the page loads, the platform binds the informat object to the window object. Designers can use informat to call functional functions provided by client scripts.

Built-in Functions

submitForm

Submit the form

javascript
this.submitForm(isValidate);
ParameterTypeDescription
isValidatebooleanWhether to validate the form when submitting. Defaults to true if not passed

closeForm

Close the form (closeForm)

javascript
this.closeForm().then(() => {
  console.log("close form");
});

Closing the form

closeForm is only valid when using controls, automations to open forms, form creation pages, and form detail pages.

reset

Reset the form (reset)

javascript
this.reset().then(() => {
  console.log("reset form");
});

getData

Get form data

javascript
this.getData(isValidate);
ParameterTypeDescription
isValidatebooleanWhether to validate the form when getting data. Defaults to true if not passed
javascript
this.getData(true).then((formData) => {
  console.log(formData);
});

validate

Validate form data

javascript
this.validate(fields);
ParameterTypeDescription
fieldsString、Array<String>The field identifiers to validate. If not passed, all fields in the form will be validated

display

Set form field display

javascript
this.display(fields);
ParameterTypeDescription
fieldsString、Array<String>The collection of field identifiers to display

hide

Set form field hide

javascript
this.hide(fields);
ParameterTypeDescription
fieldsString、Array<String>Collection of field identifiers to hide

disabled

Set field disabled state

javascript
this.disabled("name", true); // Set the field with identifier name to disabled
ParameterTypeDescription
fieldsString、Array<String>Collection of field identifiers to display
disabledBooleanWhether to disable the field. Optional parameter, defaults to true if not passed

dialogOpen

Open dialog

javascript
this.dialogOpen(dialogMode);
ParameterTypeDescription
dialogModeStringDialog identifier
javascript
// Open dialog with identifier dialogSubForm
this.dialogOpen("dialogSubForm")
  .then(function () {
    console.log("dialogOpen execute");
  })
  .catch(function (error) {
    console.log("dialogOpen execute error", error);
  });

dialogClose

Close dialog

javascript
this.dialogClose(dialogMode);
ParameterTypeDescription
dialogModeStringDialog identifier
javascript
// Close dialog with identifier dialogSubForm
this.dialogClose("dialogSubForm")
  .then(function () {
    console.log("dialogClose execute");
  })
  .catch(function (error) {
    console.log("dialogClose execute error", error);
  });

onEvent

Add event listener

javascript
this.onEvent(eventType, handler, field);
ParameterTypeDescription
eventTypeStringThe event type to listen for
handlerFunctionThe handling method to listen for
fieldStringThe field identifier that triggers the event. If not passed, it listens to all events of this type in the form

onceEvent

Add single-time event listener

javascript
this.onceEvent(eventType, handler, field);
ParameterTypeDescription
eventTypeStringThe event type to listen for
handlerFunctionThe handling method to listen for
fieldStringThe field identifier that triggers the event. If not passed, it listens to all events of this type in the form

offEvent

Remove event listener

javascript
this.offEvent(eventType, handler, field);
ParameterTypeDescription
eventTypeStringThe event type to listen for
handlerFunctionThe handling method to listen for. If not passed, all listeners under this event type are removed
fieldStringThe field identifier that triggers the event. If not passed, all listeners of this event type are removed

Complete Example

javascript
{
    props: {
        // Define page properties
        uname:{
            type:String;
        }
    },
    data: function () {
        return {
            // Define the optional data item list for the dropdown box
            sexList: [
                {
                    key: 'f',
                    label: 'Male'
                },
                {
                    key: 'm',
                    label: 'Female'
                }
            ]
        };
    },
    // When the page component creates an instance
    created: function () {

    },
    // Execute business logic after the page is mounted
    mounted: function () {
        var that = this;
        setTimeout(function () {
            that.setup();
        }, 0);
    },
    // Before the page component is destroyed
    beforeDestroy: function () {

    },
    methods: {
        // Execute custom processing after the page is mounted
        setup: function () {
            var that = this;
            // Output the properties of the context
            console.log(this.uname);
            // Set the data of the current form field (name)
            that.form.name = 'Zhang San';
            // Call the API function bound by the script
            informat.system.getToken().then(res => {
                console.log(res);
            });
            // Globally monitor page field data changes
            that.onEvent('onChange', function (data) {
                console.log('onChange', data);
            });
            // Monitor page button (buttonSubmit) click event
            that.onEvent('onClick', function (data) {
                that.getData(true).then((res) => {
                    informat.app.callAutomatic({
                        automaticId: 'formdesignerInvoker',
                        args: [res]
                    });
                    // console.log('onClick.getData',res);
                });
            }, 'buttonSubmit');
            // Monitor page button (buttonAdd) click event, then pop up a dialog box (dialog_e2duygzp)
            that.onEvent('onClick', function (data) {
                that.dialogOpen('dialog_e2duygzp');
            }, 'buttonAdd');
            // Monitor page button (buttonCancel) click event, then reset the form
            that.onEvent('onClick', function (data) {
                that.reset();
            }, 'buttonCancel');
            // Specify to monitor page field (name) data changes
            that.onceEvent('onChange', function (data) {
                console.log('onNameChange', data);
                // Get all current form data
                console.log('onNameChange.form', that.form);
            }, 'name');
            // Specify to monitor page dialog box (dialog_e2duygzp) click cancel time
            that.onceEvent('onDialogCancel', function (data) {
                console.log('onDialogCancel', data);
                that.dialogClose('dialog_e2duygzp');
            }, 'dialog_e2duygzp');
        }
    }
}