Jump to content

Issue with Events..


cristianotestai

Recommended Posts

I need a suggestion to solve a particular side effect.

There are events that are quick to be executed by the user, which not required to have a screen mask to block a transaction in the application.

As an example, we have a UniEdit and UniMemo, which sets the OnKeyDown event. When the User presses the enter key, the text of UniEdit is added on the UniMemo and the text UniEdit is clear. This is a classic example ..

 

In production mainly in cases where the text to be added is relatively large and the user presses the enter key quickly more than once, is added to the UniMemo the same text several times, ie, more than one time the event was performed ... what is wrong, because when you press the Enter key, the text of UniEdit is clear after being added to the UniMemo.

How to not allow this and other cases happen?

 

Thanks

Link to comment
Share on other sites

Javascript is asynchronous, so every time OnKeyDown event is called, browser doesn't actually add to unimemo and clear uniedit, it just generates ajax call to server. On server side you specify your actions, unigui converts them to javascript and sends it back to browser in response. And only when this generated javascript is executed, the changes happen.

Each ajax call doesn't wait for previous one to complete, so if user presses Enter quickly many times, severals ajax requests will be generated to server, each containing your current text in uniedit. Until one of them is completed and uniedit is cleared, all those requests will do the same thing - add the same text to unimemo. Thats why we need masks to prevent user from generating subsequent ajax calls until application state changes.

To make changes immediatly you'll need to write some processing logic on client side in javascript. In your case, for example, you can intercept onkeydown javascript event of uniedit and clear it from there, not on server. Or even add that text to memo and clear uniedit entirely client-side, optionally calling ajaxRequest() to inform server about changes.

Link to comment
Share on other sites

Javascript is asynchronous, so every time OnKeyDown event is called, browser doesn't actually add to unimemo and clear uniedit, it just generates ajax call to server. On server side you specify your actions, unigui converts them to javascript and sends it back to browser in response. And only when this generated javascript is executed, the changes happen.

Each ajax call doesn't wait for previous one to complete, so if user presses Enter quickly many times, severals ajax requests will be generated to server, each containing your current text in uniedit. Until one of them is completed and uniedit is cleared, all those requests will do the same thing - add the same text to unimemo. Thats why we need masks to prevent user from generating subsequent ajax calls until application state changes.

To make changes immediatly you'll need to write some processing logic on client side in javascript. In your case, for example, you can intercept onkeydown javascript event of uniedit and clear it from there, not on server. Or even add that text to memo and clear uniedit entirely client-side, optionally calling ajaxRequest() to inform server about changes.

 

Thanks for explanation zilav!

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