KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Generically assign values to and retrieve values from a form data object
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: May 15, 2023

Situation: You have a 4D form where different UI widgets (e.g., text input box, dropdown list, etc.) trigger the same form event (e.g., "On Load", "On Data Change", etc.). Instead of implementing each component's object method, you would like to configure the UI components altogether according to the triggered form event.

You can handle all the UI widgets at once in one method. When a form event occurs, you can use the FORM Event command to retrieve the FORM Event object, which contains 3 properties: objectName (not included if triggered by form), code, and description. Here, you would use the "objectName" property to identify the UI component that triggered the form event


So, you can use the structure in the following example in either a project method or form method to handle different UI widgets when the same form event is triggered:

Case of
  : (Form event code =On Data Change)
    Case of
     : (FORM Event.objectName="ObjectName")
     // add code here
     : (FORM Event  .objectName="ObjectName1")
     // add code here
    End case
End case


Example:

// Example: when the value of a input box is changed, you want to reformat it
Case of
  : (Form event code =On Data Change)
  Case of
  // change text to all uppercase format
    : (FORM Event.objectName="FullName")
      OBJECT SET VALUE(FORM Event.objectName; Uppercase(OBJECT Get value(FORM Event.objectName)))
    // change phone number input to "(XXX)-XXX-XXXX"
    // **assume that the UI component has an numeric entry filter (&9) with
    // character limit

    : (FORM Event.objectName="PhoneNumber")
      OBJECT SET VALUE(FORM Event.objectName; "("+Substring(OBJECT Get value(FORM Event.objectName); 0; 3)+\
  ")"+Substring(OBJECT Get value(FORM Event.objectName); 4; 3)+"-"+Substring(OBJECT Get value(FORM Event.objectName); 7; 4))
  End case
End case


FORM Event command documentation: https://doc.4d.com/4Dv19R8/4D/19-R8/FORM-Event.301-6102252.en.html