Skip to main content
Version: 53.0.0

Відкриття користувацьких спливаючих форм

The Script Module support opening of custom popups. Some forms (document, task, user dictionary) have the built-in support of the event.openPopupForm method that is used for that. Additionally, there is a hint for custom buttons for a code snippet for opening some popups. Also, for any other places where the event.openPopupForm is not supported in the script module the same function we can just import from the forms package:

const {showPopupForm} = require('@unitybase/forms/public/forms-public.js')

The event.openPopupForm and the showPopupForm methods are the same and support two arguments:

  • the first required argument is an popup's code - string with value of some entry of the frm_PopForm entity
  • the second parameter is optional, it allows configuring:
    • title - popup window title
    • height - popup's height as css value of "height" property. Supports px, auto, and vh units
    • width - popup's width as css value of "width" property. Supports px, auto, and vw units
    • attrValues - Initial popup's form values. If not provided, will use default initial values configured in the popup designer

Examples

Example: open "lastNameFirstNamePopup" popup form with config to fill "fullName" document attribute​

Assuming 40 is nodeId for a button on form, add an async form_39_click event handler and use await event.openPopupForm('lastNameFirstNamePopup') to open popup and wait until it closed. Pass into the popup current attribute values and set height and width. Use popupResult.attrValues to set fullName attribute value:

module.exports = {
async form_40_click(event) {
const popupResult = await event.openPopupForm('lastNameFirstNamePopup', {
title: 'Enter your last name and first name',
height: '400px',
width: '400px',
attrValues: {
lastName: event.document.getAttribute('lastName'),
firstName: event.document.getAttribute('firstName')
}
})

if (popupResult) {
const enteredValues = popupResult.attrValues
const fullName = enteredValues.lastName + ' ' + enteredValues.firstName
event.document.setAttribute('fullName', fullName)
}
}
}

Example: show a popup without using event.openPopupForm, as a custom document action confirmation dialog​

Import showPopupForm from public part of @unitybase/forms packet.

const {showPopupForm} = require('@unitybase/forms/public/forms-public.js')

module.exports = {
async action_beforeExecute_approve(event) {
event.skipStandardConfirmDialog()

const popupResult = await showPopupForm('approveActionPopup')

if (!popupResult) {
event.cancelAction()
return
}

const additionalInfo = popupResult.attrValues.additionalInfo
event.document.setAttribute('approveResultInfo', additionalInfo)
}
}