Jump to content


Photo

How do prevent double click on a control?


  • Please log in to reply
6 replies to this topic

#1 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 13 April 2016 - 12:19 PM

Hello,

 

when I double click on a clickable control, that action is executed twice. And when I create and show a form it is twice created and somehow overlapping the underlying (parent) form. In other words, the app doesn't work anymore.

 

Is there a prefered way to diactivate all clickable controls, when a form is showing (transformation)? And when I go back to activate it again?



#2 Igor Savkic

Igor Savkic
  • Members
  • 185 posts

Posted 13 April 2016 - 02:41 PM

> when I double click on a clickable control, that action is executed twice. And when I create and show a form it

 

When you double click do you get two click events or two double clicks events?

If it's two click events then that is normal behaviour, but if it's two double click that is odd if it happens for same control and event handler.

 



#3 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 13 April 2016 - 03:02 PM

I know, that is a normal behaviour, but what is the prefered way to prevent it? Especially, that a form is not loaded twice.



#4 Igor Savkic

Igor Savkic
  • Members
  • 185 posts

Posted 13 April 2016 - 03:20 PM

> I know, that is a normal behaviour, but what is the prefered way to prevent it? Especially, that a form is not loaded twice.

 

If you need to handle both click and double click on same control then you have to do it yourself.

Solution I'm mostly using is on first click event to add a timer (small one) that would call actual onClick handler when it expires or if you receive DblClick event before timer is due, that timer is cancelled and you do regular DblClick handling.



#5 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 13 April 2016 - 03:54 PM

No, I don't need the double click. On touch devices, you just tab on a control, and sometimes the click event is executed twice. Also if someone does a couble click the click action is executed twice.

 

Is there a general mechanism to disable events on a form, in order I don't need to it on every single control, with a click event?

During showing a new form (transform effect), to user should also not click to any other control, during animiation.



#6 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 13 April 2016 - 04:24 PM

Found a pretty good way on stackoverflow to disable all events on my form :)

http://stackoverflow...s-in-javascript

procedure TForms.BlockForm;
begin
  _blockForm := TW3DIVHtmlElement.Create(_containerView);
  w3_setStyle(_blockForm.Handle, 'position', 'absolute');
  w3_setStyle(_blockForm.Handle, 'left', '0');
  w3_setStyle(_blockForm.Handle, 'top', '0');
  w3_setStyle(_blockForm.Handle, 'height', '100%');
  w3_setStyle(_blockForm.Handle, 'width', '100%');
  w3_setStyle(_blockForm.Handle, 'z-index', '99999');

  w3_setTimeout(
    procedure
    begin
      if Assigned(_blockForm) then
        _blockForm.Free;
    end,
    500);

end;


#7 Igor Savkic

Igor Savkic
  • Members
  • 185 posts

Posted 13 April 2016 - 04:30 PM

> No, I don't need the double click. On touch devices, you just tab on a control, and sometimes the click event is executed twice. Also

> if someone does a couble click the click action is executed twice.

 

If you handle clicks with addEventListener instead of relying on RTL to send you events you can try with stop propagation call (I don't know if it will help)

 

Here is example I'm using for ListBox

lbMain.Handle.addEventListener('click', @OnCustClick, False);

 

procedure TfrmClientDetails.OnCustClick(evt: JEvent);
begin
  evt.stopImmediatePropagation();
  evt.stopPropagation();

  ...
end;

 

I don't have a tablet to test but perhaps right event to handle is touchstart instead of click. In any case I think you'll have to do manual handling of duplicating events.
 

> Is there a general mechanism to disable events on a form, in order I don't need to it on every single control, with a click event?

> During showing a new form (transform effect), to user should also not click to any other control, during animiation.

 

I don't know if there's some official SMS way, but just few ideas, before starting transition try to

1) add click handler for whole document BrowserAPI.Document (or call SetCapture on some control), that should prevent other controls of receiving it

2) create some panel (like TW3BlockBox) over entire Form (or Display) that should prevent other controls of receiving events.

 

I see you already found a solution, that's I guess is this variant 2). Thanks for sharing code, it might come in handy.

 

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users