estrify Posted April 17, 2023 Share Posted April 17, 2023 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, Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 17, 2023 Share Posted April 17, 2023 Hello @estrify 3 hours ago, estrify said: but I can't with ClientEvents.UniEvents (specifically, "beforeInit"). Should work, give the component a Name. Quote Link to comment Share on other sites More sharing options...
estrify Posted April 17, 2023 Author Share Posted April 17, 2023 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, Quote Link to comment Share on other sites More sharing options...
estrify Posted April 20, 2023 Author Share Posted April 20, 2023 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, 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.