Jump to content

Create dinamic component and set uniEvents


Wilton Ergon

Recommended Posts


I create tunimdatepicket controls dynamically, but I can't set the aftercreate event to change the button's title.

the code below works when the component is already on the screen. but it doesn't work when it's created dynamically.

 

 

var cDateTimePicker:TUniMDatePicker

 

                    cDateTimePicker                  := TUniMDatePicker.Create(self);
                    cDateTimePicker.ClientEvents.UniEvents.Values['afterCreate'] :=
                                                      'function afterCreate(sender) '+
                                                      '{ '+
                                                      '    var me=sender.getPicker(); '+
                                                      '    if (me && !Ext.isWindows) { '+
                                                      '        me.getDoneButton().setText("OK"); '+
                                                      '        me.getCancelButton().setText("X") '+
                                                      '    } '+
                                                      '}';

Link to comment
Share on other sites

3 minutes ago, wilton_rad said:


I create tunimdatepicket controls dynamically, but I can't set the aftercreate event to change the button's title.

the code below works when the component is already on the screen. but it doesn't work when it's created dynamically.

 

 

var cDateTimePicker:TUniMDatePicker

 

                    cDateTimePicker                  := TUniMDatePicker.Create(self);
                    cDateTimePicker.ClientEvents.UniEvents.Values['afterCreate'] :=
                                                      'function afterCreate(sender) '+
                                                      '{ '+
                                                      '    var me=sender.getPicker(); '+
                                                      '    if (me && !Ext.isWindows) { '+
                                                      '        me.getDoneButton().setText("OK"); '+
                                                      '        me.getCancelButton().setText("X") '+
                                                      '    } '+
                                                      '}';

Hi

Can you please create a test case?

Link to comment
Share on other sites

  • 3 weeks later...

I still have the issue, just with a TUniLabel.

ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){config.cls = "app-h3 app-color-primary";}';

Does not work with 1549 build.

Have to do it like this because the "LayoutConfig.Cls" property is protected and not public, yet is is published.

Link to comment
Share on other sites

25 minutes ago, GerhardV said:

I still have the issue, just with a TUniLabel.

ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){config.cls = "app-h3 app-color-primary";}';

Does not work with 1549 build.

Have to do it like this because the "LayoutConfig.Cls" property is protected and not public, yet is is published.

Can you check below code?

with unilabel1, jsinterface do
  jsconfig('cls', ['app-h3- app-color-primary']);

 

Link to comment
Share on other sites

Thanks Hayri, yes I already done that and it works just fine, but I would really want the LayoutConfig.Cls property to be public. To me published implies public.

I would also like to know why the setting of the UniEvents value isn't working, that should be fine because the TUniLabel is created on the "server side" at the point in time, unless I am missing something.

Link to comment
Share on other sites

1 hour ago, GerhardV said:

I still have the issue, just with a TUniLabel.

ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){config.cls = "app-h3 app-color-primary";}';

Does not work with 1549 build.

Hello,

Are you creating the component dynamically at runtime?

Link to comment
Share on other sites

Dynamically on the UniFormCreate method:

with TUniLabel.Create(Self) do begin
  Caption := 'Blah';
  Align:= alTop;
  CreateOrder := index+1;
  LayoutConfig.Margin := '10 10 5 10';
  //This doesn't work
  //ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){config.cls = "app-h3 app-color-primary";}';
  //This work
  JSInterface.JSConfig('cls',['app-h3 app-font-600 app-color-secondary']);
  Parent := pnlClientArea;
end;

This happens in a loop which creates several labels. The parent container is a panel with the layout set to vbox.

What is your definition of runtime or dynamically?

Link to comment
Share on other sites

1 hour ago, GerhardV said:

with TUniLabel.Create(Self) do begin Caption := 'Blah'; Align:= alTop; CreateOrder := index+1; LayoutConfig.Margin := '10 10 5 10'; //This doesn't work //ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){config.cls = "app-h3 app-color-primary";}'; //This work JSInterface.JSConfig('cls',['app-h3 app-font-600 app-color-secondary']); Parent := pnlClientArea; end;

Okay,

Assign a name to the component.

with TUniLabel.Create(Self) do begin
  Caption := 'Blah';
  Align:= alTop;
  Name := ...

 

Link to comment
Share on other sites

Of course yes - thanks!

Which method will result in less network traffic?

1. ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){config.cls = "app-h3 app-color-primary";}';

or

2. JSInterface.JSConfig('cls',['app-h3 app-font-600 app-color-secondary']);

Since we don't have the source code of UniGuiClasses, I assume that (1.) is happening on the server side while the "client JavaScript" is being constructed, whereas with (2.)  the call is only happening afterwards as the JavaScript has already been constructed?

Maybe @Farshad Mohajeri can shed some light on when what is happening and which is better practice?

I still would like to know why LayoutConfig.Cls is not public.

Link to comment
Share on other sites

You are probably referring to the payload, I was more wondering about round trips between the browser and server.

In the case of  "JSInterface.JSConfig" I was wondering if the application JS get constructed and send to the browser and only after that the "JSInterface.JSConfig('cls',['app-h3 app-font-600 app-color-secondary']); call is send to the browser. I did a small test and it seems that both gets build on initial construction of the application JS.

O13 = new Ext.form.Label({
    id: "O13_id",
    beforeinit: function (sender, config) {
      config.cls = "app-h3 app-color-primary";
    },
    text: "ClientEvents.UniEvents",
    x: 32,
    y: 24
});
O13.nm = "O13";
_cdo_("UniLabel1", O13, null, MainForm);
O17 = new Ext.form.Label({
    id: "O17_id",
    cls: "app-h3 app-font-600 app-color-secondary",
    text: "JSInterface.JSConfig",
    x: 368,
    y: 24
});
O17.nm = "O17";
_cdo_("UniLabel2", O17, null, MainForm);

So I will then expect if LayoutConfig.Cls is public it will also result in:

O17 = new Ext.form.Label({
  id: "O17_id",
  cls: "app-h3 app-font-600 app-color-secondary",
  text: "JSInterface.JSConfig",
  x: 368,
  y: 24
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...