Jump to content


Photo

Close Form


  • Please log in to reply
12 replies to this topic

#1 Volk65

Volk65

    Active Member

  • uniGUI Subscriber
  • PipPipPip
  • 63 posts
  • LocationMSK, Russia

Posted 09 January 2018 - 11:35 AM

Hi all!

 

I showed the form: MyForm.Show().

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


  • 0

#2 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 09 January 2018 - 03:42 PM

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,


  • 0

#3 Volk65

Volk65

    Active Member

  • uniGUI Subscriber
  • PipPipPip
  • 63 posts
  • LocationMSK, Russia

Posted 09 January 2018 - 04:44 PM

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?

Attached Files


  • 0

#4 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 09 January 2018 - 09:16 PM

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

  • 0

#5 Volk65

Volk65

    Active Member

  • uniGUI Subscriber
  • PipPipPip
  • 63 posts
  • LocationMSK, Russia

Posted 09 January 2018 - 09:31 PM

Thank you! what I needed.


  • 0

#6 Volk65

Volk65

    Active Member

  • uniGUI Subscriber
  • PipPipPip
  • 63 posts
  • LocationMSK, Russia

Posted 11 January 2018 - 01:13 PM

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!

Attached Files


  • 0

#7 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 11 January 2018 - 02:37 PM

Hi,

Ok I will check
  • 0

#8 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 11 January 2018 - 04:28 PM

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

  • 0

#9 Volk65

Volk65

    Active Member

  • uniGUI Subscriber
  • PipPipPip
  • 63 posts
  • LocationMSK, Russia

Posted 11 January 2018 - 05:00 PM

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:

Attached File  Screenshot_11.png   25.24KB   1 downloads

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.


  • 0

#10 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 11 January 2018 - 05:05 PM

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

  • 0

#11 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 11 January 2018 - 05:06 PM

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

 

Yes of course, I will try...


  • 0

#12 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 5011 posts

Posted 11 January 2018 - 05:23 PM

But at the moment, does this solution work for your case ?!


  • 0

#13 Volk65

Volk65

    Active Member

  • uniGUI Subscriber
  • PipPipPip
  • 63 posts
  • LocationMSK, Russia

Posted 11 January 2018 - 06:10 PM

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.

Attached File  Screenshot_12.png   31.84KB   1 downloads

Attached File  Screenshot_13.png   42.93KB   0 downloads

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.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users