Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: Nuno T. on June 14, 2017, 05:24:56 pm



Title: create button dynamically
Post by: Nuno T. on June 14, 2017, 05:24:56 pm
Hi all,


I have one problem to create one button dynamically.
With this code i can create a button, but if i press it nothing happens.

Can someone helps please ?

       ON ACTION button1       
         IF i = 0 THEN
           LET c = n.getFirstChild()
           LET l2 = c.createChild("Button")
           LET i = l2.getId()
           DISPLAY "I:",i
           CALL l2.setAttribute("name","bt1")
           CALL l2.setAttribute("text","BUTTON")
           CALL l2.setAttribute("actionActive","1" )
           CALL ui.interface.refresh()
         END IF       

ON ACTION bt1
  DISPLAY "TEST"


Title: Re: create button dynamically
Post by: Leo S. on June 16, 2017, 11:56:16 pm
Hi Nuno, your problem is probably that you expect to have the button working in one and the same dialog.
But for all action views the internal binding is done *before* the dialog actually starts, so the runtime system is not aware about your dynamically created button.
If you leave the current dialog and reenter it then it will work (or go to another dialog) .
Definitively not needed:
  CALL l2.setAttribute("actionActive","1" ) -- the runtime takes care about actionActive
  CALL ui.interface.refresh() -- the UI is always refreshed when going interactive

    My advise would be however to have a hidden button in your form and show it on demand with DIALOG.setElementHidden(<buttonname>,FALSE)
    because you will have the problem of where to place the button (assuming grid layout) and the risk is there that you specify invalid coordinates   (which either may lead to overlapping of existing elements or odd rendering of the client)
   Attached sample shows how to create the button dynamically and how to show a hidden button.

Regards, Leo