NetTalk Central

Author Topic: Unwanted record Insert when Esc key pressed  (Read 5486 times)

webwilcox

  • Newbie
  • *
  • Posts: 31
    • View Profile
    • Email
Unwanted record Insert when Esc key pressed
« on: February 28, 2013, 01:31:15 PM »
I have a form that is called via a Popup from a browse.  When the user clicks the insert button, the form comes up just fine to add a new record.  If the user presses the Esc key on the keyboard, a blank record is inserted and all field validation is skipped.  The unique key is generated and all primed fields are filled in.  I would want the Esc key to act like pressing the "Cancel" button on the form.  Is there easy I am missing somewhere.

Using Clarion 6.3 and Nettalk 6.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Unwanted record Insert when Esc key pressed
« Reply #1 on: February 28, 2013, 09:31:03 PM »
Hi

So there are two possible ways for a form to work when Inserting a record.

a) add record with primed values when form opens, save other stuff when user clicks on Save.

b) Open the form, but don't write anything to the disk unless the user clicks on Save.

You can control which one is used on the Advanced tab of the form. The system will "decide" which one to use based on a couple rules.

While (a) is the normal Clarion windows approach, it can leave you with "half-hearted" records if the program crashes, or is terminated, while the form procedure is open. Not a big deal in a windows program, but because a user can abandon a form in many ways on the web, this happens substantially more on the web.

However (b) doesn't work if you are adding child records at the same time as the parent record (think Invoice form with LineItems).

So NetTalk will try and do (b), but will fall back on (a) if the form contains a child browse. As I said earlier you can override the behaviour on the Advanced tab of the Form.

Given that users can abandon forms in all kinds of ways (url in address bar, close tab in browser, close browse, close windows, whatever) there's no way to "catch" all those cases. Rather the best approach is to have a field, called say "HalfHearted" which is primed to 1 on the priming tab.
And Set to 0 in the ValidateInsert routine.

Thus all abandoned records will have halfHearted=1 and so they can be removed with a background procedure. (You might want to record the date/time in the field so you know how long it has been abandoned for...)

Cheers
Bruce

webwilcox

  • Newbie
  • *
  • Posts: 31
    • View Profile
    • Email
Re: Unwanted record Insert when Esc key pressed
« Reply #2 on: March 01, 2013, 11:02:24 AM »
Thanks Bruce.  That explains it very well.

Is there a way to keep the Escape key from exiting the popup from in the browser ?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Unwanted record Insert when Esc key pressed
« Reply #3 on: March 01, 2013, 10:59:54 PM »
yes, if you right click on the form,
search for
Start of "Set jQuery Dialog Options"
there you can set
loc:options = p_web.SetOption(loc:options,'closeOnEscape',0)
(I've not tested it, but give it a try.)

Cheers
Bruce

webwilcox

  • Newbie
  • *
  • Posts: 31
    • View Profile
    • Email
Re: Unwanted record Insert when Esc key pressed
« Reply #4 on: March 04, 2013, 05:58:30 AM »
I get the following when I give it a try.

Syntax error: Field not found: SETOPTION
Syntax error: unknown function label.

different method ?

Thanks for your help.

webwilcox

  • Newbie
  • *
  • Posts: 31
    • View Profile
    • Email
Re: Unwanted record Insert when Esc key pressed
« Reply #5 on: March 04, 2013, 08:34:34 AM »
After a little digging, I added the following in the embed and it worked.

loc:options = clip(loc:options) & ',closeOnEscape: false'

Thanks for pointing me in the right direction.

Brad

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Unwanted record Insert when Esc key pressed
« Reply #6 on: March 04, 2013, 10:35:25 PM »
ahh, yes, sorry, I didn't note you were on NT6, and SetOption is an NT7 feature.
Your solution is fine.

cheers
Bruce