Volk65 Posted January 9, 2018 Share Posted January 9, 2018 Hi all! I showed the form: MyForm.Show(). How do I close the form by clicking outside the form (Nonclient area) ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 9, 2018 Share Posted January 9, 2018 Hi, Maybe you wanted like this: For example for UniForm1: 1. UniForm1 -> ClientEvents -> ExtEvents -> function window.show: function window.show(sender, eOpts) { var me=sender; me.clicklistener = function(){ ajaxRequest(me, '_close', []); }; document.addEventListener('click', me.clicklistener, false); } 2. UniForm1 -> ClientEvents -> ExtEvents -> function window.beforedestroy: function window.beforedestroy(sender, eOpts) { var me=sender; document.removeEventListener('click', me.clicklistener, false); } 3. UniForm1 -> OnAjaxEvent: procedure TUniForm1.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_close' then Close end; Best regards, Quote Link to comment Share on other sites More sharing options...
Volk65 Posted January 9, 2018 Author Share Posted January 9, 2018 Hi!Yes works, BUT if you click the mouse on the form itself or any control on that form also closes. I made a simple example. Note: normally, to close a form in VCL I use the TForm.OnDeactivate, which is triggered when focus is lost.I saw in ClientEvents.ExtEvents the trigger window.deactivate, maybe it can use? Test4.rar Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 9, 2018 Share Posted January 9, 2018 Hi, UniForm1 -> ClientEvents -> ExtEvents -> function window.show replace to: function window.show(sender, eOpts) { var me=sender; me.clicklistener = function(e){ ajaxRequest(me, '_close', []); }; document.addEventListener('click', me.clicklistener, false); me.el.dom.addEventListener('click', function(e){e.stopPropagation()}); //<-------------- } Quote Link to comment Share on other sites More sharing options...
Volk65 Posted January 9, 2018 Author Share Posted January 9, 2018 Thank you! what I needed. Quote Link to comment Share on other sites More sharing options...
Volk65 Posted January 11, 2018 Author Share Posted January 11, 2018 Hi Delphi Developer! As it turned out not so simple. If a form contains a combobox after selecting from the list also closes the form.Best wishes! Test41.rar Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 11, 2018 Share Posted January 11, 2018 Hi, Ok I will check Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 11, 2018 Share Posted January 11, 2018 Fast solution...: function window.show(sender, eOpts) { var me=sender; me.isOk=true; me.clicklistener = function(e){ if (e.target.boundView){ me.query('combobox').forEach(function(el){ if (e.target.boundView == el.getPicker().id) { me.isOk=false; } }); }; if (me.isOk) { ajaxRequest(me, '_close', []); }; }; document.addEventListener('click', me.clicklistener, false); me.el.dom.addEventListener('click', function(e){e.stopPropagation()}); } Quote Link to comment Share on other sites More sharing options...
Volk65 Posted January 11, 2018 Author Share Posted January 11, 2018 Thanks for the help!Sorry I have not only combobox, but there are uniDBComboBox, uniDBLookupCombobox. Maybe there's some other solution? I use these forms to define the filter entries and is used in many forms/frames: It is often used in the web interface shows a form (not modal), and one click of the mouse outside of the form - the form is closed. This is a beautiful solution to which users quickly get used to. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 11, 2018 Share Posted January 11, 2018 Edited function window.show(sender, eOpts) { var me=sender; //me.isOk=true; //<------------- me.clicklistener = function(e){ me.isOk=true; //<------------- if (e.target.boundView){ me.query('combobox').forEach(function(el){ if (e.target.boundView == el.getPicker().id) { me.isOk=false; } }); }; if (me.isOk) { ajaxRequest(me, '_close', []); }; }; document.addEventListener('click', me.clicklistener, false); me.el.dom.addEventListener('click', function(e){e.stopPropagation()}); } Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 11, 2018 Share Posted January 11, 2018 Sorry I have not only combobox, but there are uniDBComboBox, uniDBLookupCombobox. Maybe there's some other solution? Yes of course, I will try... Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 11, 2018 Share Posted January 11, 2018 But at the moment, does this solution work for your case ?! Quote Link to comment Share on other sites More sharing options...
Volk65 Posted January 11, 2018 Author Share Posted January 11, 2018 Partially. As I said, all is not so simple. Sorry. But in one of the menu item invokes another dialog: enter a range of dates. after displaying the dialog "date range" - the OK button does not fire the event "OnClick" of the dialog "Set Filter". Let's do the following. I withdraw the question. In the end, it's not super important. But if suddenly you find the solution - write. 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.