Jump to content
markus_ja

How do prevent double click on a control?

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

http://stackoverflow.com/questions/14372690/temporarily-disable-all-events-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;

Share this post


Link to post
Share on other sites

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

 

 

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

×