Jump to content

Setting ClientEvents.ExtEvents when creating custom component


estrify

Recommended Posts

Dear @Sherzod,

I am creating a custom component that descends from TUniPanel. For this new compnent, I need to set ClientEvents.ExtEvents and ClientEvents.UniEvents. I can set some ClientEvents.ExtEvents inside LoadCompleted, but I can't with ClientEvents.UniEvents (specifically, "beforeInit"). Where do I have to do this?...

  • If I set it inside WebCreate, there is no effect...
  • If I set it inside the constructor, this will insert the new panel with the hardcoded javascript in design mode, so if I change the javascript in the component source, I have to remove all the panels and insert them again throughout the project, for what this is unacceptable.

So where is the most suitable point to do this?

Sincerely,

Link to comment
Share on other sites

Hi @Sherzod,

Thanks for response, but I'm afraid I didn't explain myself well. Let me try to explain it better:

  • I am developing a component:
type TMyUniPanel = class(TUniPanel) ...
  • And I have something like this:
procedure TMyUniPanel.WebCreate;
begin
  inherited;
  ClientEvents.ExtEvents.Values['beforerender'] := 'function beforerender(sender, eOpts){ sender._log = sender._log ?? "" + "\nExtEvents-beforerender"; }';
  ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){ sender._log = sender._log ?? "" + "\nUniEvents-beforeInit"; }';
end;
  • Now, when I want to use this component in a form, inserting it and performing the following:
    UniSession.AddJS('alert('+MyUniPanel1.JSName+'._log);');

    the result is "UniEvents-beforeInit" and not both "ExtEvents-beforerender" and "UniEvents-beforeInit". That is, “beforerender” has not been executed.

So, when developing a component, where is the most suitable point to assign code to ClientEvents.ExtEvents.Values['beforerender']?

Best regards,

 

 

 

Link to comment
Share on other sites

Hi,

In case anyone is interested, I have found that the following approach would solve the problem:

procedure TMyUniPanel.WebCreate;
begin
  inherited;
  ClientEvents.UniEvents.Values['beforeInit'] := 'function beforeInit(sender, config){ '+
      'sender._log = sender._log ?? "" + "\nUniEvents-beforeInit"; '+
    '}';
  ClientEvents.UniEvents.Values['afterCreate'] := 'function afterCreate(sender, config){ '+
      'sender.on("beforerender", function(sender, eOpts){ '+
        ' sender._log = sender._log + "\nExtEvents-beforerender"; '+
      '}); '+
    '}';
end;

 

Best regards,

 

  • Thanks 1
Link to comment
Share on other sites

  • estrify changed the title to Setting ClientEvents.ExtEvents when creating custom component

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...