Jump to content
uniGUI Discussion Forums
Volk65

Close Form

Recommended Posts

Hi all!

 

I showed the form: MyForm.Show().

How do I close the form by clicking outside the form (Nonclient area) ?

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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()}); //<--------------
}

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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()});
}

Share this post


Link to post
Share on other sites

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:

post-4024-0-07041700-1515689634_thumb.png

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.

Share this post


Link to post
Share on other sites

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()});
}

Share this post


Link to post
Share on other sites

Sorry I have not only combobox, but there are uniDBComboBox, uniDBLookupCombobox. Maybe there's some other solution?

 

Yes of course, I will try...

Share this post


Link to post
Share on other sites

Partially.

As I said, all is not so simple. Sorry. :rolleyes: But in one of the menu item invokes another dialog: enter a range of dates.

post-4024-0-99987800-1515693345_thumb.png

post-4024-0-06948600-1515693353_thumb.png

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×