This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v20 R7
Dynamic Forms

Dynamic Forms  


 

Dynamic Forms are forms whose structures are defined in either a .json file or a 4D object. They are regenerated each time they are run and provide a superior level of flexibility. A few notable advantages include: 

  • Usability
    • straightforward updates
    • dynamic user modifications
    • easy reuse
    • faster searching
  • Portability
    • simplified sharing
    • can be stored in source control

Every object defined in a dynamic form, including the form itself, has one or more properties.

The following is a simple JSON file ("HW.json", stored in the Resources folder) with text, an image and a button:

{
    "windowTitle": "Hello World",
    "windowMinWidth": 220,
    "windowMinHeight": 80,
    "method": "HWexample",
    "pages": [
        null,
        {
            "objects": {
                "text": {
                "type": "text",
                "text": "Hello World!",
                "textAlign": "center",
                "left": 50,
                "top": 120,
                "width": 120,
                "height": 80
                },
                "image": {
                "type": "picture",
                "pictureFormat": "scaled",
                "picture": "/RESOURCES/Images/HW.png",
                "alignment":"center", 
                "left": 70,
                "top": 20, 
                "width":75, 
                "height":75        
                },
                "button": {
                "type": "button",
                "text": "OK",
                "action": "Cancel",
                "left": 60,
                "top": 160,
                "width": 100,
                "height": 20
                }
            }
        }
    ]
}

This form can be loaded in a dialog with the following 4D code:

 Open form window("/RESOURCES/HW.json")
 DIALOG("/RESOURCES/HW.json")

Which displays the form:

When creating forms from files, they must:

  • comply with the JSON schema. The 4D JSON form schema can be found in the 4D program folder at: Resources/formsSchema.json. It is your responsibility to verify the validity of the .json form file. See the JSON Validate command.
  • be in files with a ".json" file extension.
  • be stored inside the application package, relative to the structure file.

Notes:

  • Comments within .json files must be contained within the "comments" property. Standard coding characters for comments (i.e., "//", "/*", "'", etc.) will render the file invalid.
  • Arrays in JSON act as collections in 4D.

All file paths can be relative or absolute. They must use '/' as path delimiter and are resolved the following way:

  • A relative path must not start with '/'. It is resolved relatively to the JSON document where the path string has been found,
  • An absolute path starts with '/'. For security reasons, only "/RESOURCES" is accepted as absolute path and designates the current database resources folder. For example, "/RESOURCES/templates/myfile.json" points to the file "myfile.json" located in the current database resources folder.

Notes:

  • The name resolution is case sensitive.
  • 4D does not resolve a path to a .json file located over the network (starting with "http/https").
  • If the path is incorrect or the file is not valid per the JSON schema, an error will be generated.

Dynamic forms can contain JSON pointers. JSON pointers are automatically resolved when you call a 4D command that accepts a dynamic form as parameter (.json file path or 4D object):

For more information about JSON pointers, please refer to the Defining JSON Pointers section.

Documentation moved

The documentation in this section has been updated and moved to developer.4d.com in the following sections:



See also 

Overview

 
PROPERTIES 

Product: 4D
Theme: Building forms

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

4D Design Reference ( 4D v20 R7)