2

It's easy to catch events from 4D object's methods of 4D binary form (traditional 4D form) but didn't find any clue to do this in the json dynamic form.

I already gave a try with some 4D commands (CALL FORM, CALL WORKER or POST OUTSIDE CALL) as well to install a project method for a form side by side in a new process inside a loop where I handled events inside that project method. But couldn't get around it. Also I couldn't find any solution/example for this in kb or 4D blog or anywhere.

So any example or database template would be more helpful.

Ravi
  • 31
  • 5
  • I've updated a question to more clearer now. Could someone please help me to get this? Thanks. – Ravi Jul 25 '18 at 07:41

1 Answers1

2

Ravi,

Simply string them in an array named "events".

The docs are your friend for things like this: 4D Manual/Dynamic Forms#Events

The "events" property accepts a JSON array (collection) of strings or numbers. To call an event, enter the event's name or value (see form event constant values). For exemple, "events":["onLoad"]) or "events":[1]

I don't know if you can mix the literal and numeric references. I would expect so but haven't actually tested that.

Edit: Ravi, if by "catch events in code" you mean have the form you've dynamically created respond to them then you will need to include the name of a project method in the "method" tag. You can't just write some code into an object when you build it dynamically, like you can in regular 4D, but you can call a project method. In that method you can use a Case of statement to test the Form event function to determine which event fired and respond appropriately.

You can't pass parameters to this method. But you can use Object get name or Object get pointer commands to determine the particular object that called it.

For example, let's say I include myMethod as the method. The code for myMethod might look like this:

 Case of
  :(Form event=On Clicked) // on Clicked is a 4D constant
    // do something
  :(Form event=on Data Change)
    // do something else
  End case

Or

 Case of
  :(Object get name(Object current)="myButton")
    Case of
      :(Form event=on Clicked)
         ...
    End case
  :(Object get name(Object current)="anotherName")
    Case of
      :(Form event=on Clicked)
         ...
    End case
 End case

This illustrates two approaches: 1) you write a separate method for each object or 2) write a single method and determine which object called it. I prefer #2 but that's strictly my opinion.

kirkBrooks
  • 91
  • 5
  • Hi Tim, sorry I should've made this more clearer before. Actually I've already added event names in an array of string on "events" property of form object variable. But I'm stuck on how to catch that event in codes when it fires from the form or sub-form UI? It's easy to catch events from 4D object's methods of 4D binary form (traditional 4D form) but didn't find any clue to do this in the json dynamic form. – Ravi Jul 24 '18 at 07:11
  • I already gave a try with some 4D commands (CALL FORM, CALL WORKER or POST OUTSIDE CALL) as well to install a project method for a form side by side in a new process inside a loop where I handled events inside that project method. But couldn't get around it. Also I couldn't find any solution/example for this in kb or 4D blog or anywhere. So any example or database template would be more helpful. – Ravi Jul 24 '18 at 07:11