NetTalk Central

Author Topic: Validate loc vars on memory form  (Read 4499 times)

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Validate loc vars on memory form
« on: October 31, 2011, 06:56:46 AM »
I'm using a memory form to prompt the user for filtering data to be used in a browse. Everything works nicely except that some of the fields are marked as required on the form but no validation takes place.

I must be missing something ...

Update: If I touch the field (eg enter a space) _then_ the validation kicks in.

Peter
Using C6.3 and NT 5.39
« Last Edit: October 31, 2011, 07:33:53 AM by peterH »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Validate loc vars on memory form
« Reply #1 on: October 31, 2011, 07:41:32 AM »
Hi Peter,

The validation takes place "on change" - so the field has to be changed to spark it off, or the "save" button (which you probably don't have in this case) must be pressed. 

So I understand what you're doing, but it might be better to prime the local variable (using Priming tab) to some legal value to start the ball rolling.

cheers
Bruce

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: Validate loc vars on memory form
« Reply #2 on: October 31, 2011, 09:14:27 AM »
Hi Bruce,

Unfortunately there are no known or meaningful legal values to be used for priming. It's a completely open search in a data base holding debtors with bad credits so we need some name and address info in order to find something/someone.

Rather that letting the users search in vain (no name - no result!) it would be nice to be able to somehow alert them. Maybe I can find another approach.

Peter

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: Validate loc vars on memory form
« Reply #3 on: January 06, 2012, 08:58:32 AM »
Hi Bruce,

Still fighting this one  :(

You're right in that I don't have a save button. But I do have a (search) button and I've found that I can test for the value of various loc.vars in Validate::searchbutton Routine.

Now, if I could only trigger the loc:var::validate routines when I find a required var being empty. I've tried (in Validate::searchbutton Routine)

if p_web.gsv('loc:var') = ''
   do validateRecord
end

but that doesn't do it. Can you point me in the right direction - or am I on a completely wrong path here?

Thanks
Peter

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Validate loc vars on memory form
« Reply #4 on: January 09, 2012, 12:55:34 AM »
Hi Peter,

Validation can be especially difficult to discuss in the abstract, because there are so many options and flavors that might apply. Can you post a minimal example here and then I've got something concrete to comment on?

cheers
Bruce


peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: Validate loc vars on memory form
« Reply #5 on: January 09, 2012, 06:39:09 AM »
I finally figured it out!

And here's how in case others need this functionality:

If you've got a webform with some local variables that you want to use for something (e.g. a report or  filtering a browse) - and you want to make sure those local variables are filled out by the user - then it takes a tiny bit of hand coding.

As Bruce pointed out earlier in this thread the validation only kicks in when the fields are being changed or you save the form. But in this case there's nothing to save - and nothing has changed (and that's exactly what I want to catch). So I've defined a button and named it 'Search'. This button really only triggers a reset of the browse to apply the new filter.

But now that I've got this button, I add this bit of code in the server side code embed:

if p_web.gsv('loc:var') = ''
   loc:invalid = 'loc:var'
   loc:var:IsInvalid = true
   loc:alert = 'You must fill out loc:var!')
   do SendAlert
   do comment::loc:var  ! This allows the comment style to be updated
end

Remember to add this code for each field that you want to validate (all in the same embed).

Now I've got the same validation of my local variable that I would have had for a database field (and I could test for anything - not just blanks).

Peter