Jump to content

Close Form


Volk65

Recommended Posts

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,

Link to comment
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

Link to comment
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()}); //<--------------
}
Link to comment
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()});
}
Link to comment
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.

Link to comment
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()});
}
Link to comment
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.

Link to comment
Share on other sites

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