• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Validatation

Experts,
       I have 20 fields (desc1, desc2, desc3........) that is hidden depending upon the user's input. Sample, if user inputs 5 then 5 desc1... fields will be displayed. Now, the problem I need to validate if all 5 desc and it must NOT be empty (the user can also pick 10 or more).
       Is there a a more efficient way to validate (maybe loop)?
Thank you!  
 
0
cyle
Asked:
cyle
1 Solution
 
SysExpertCommented:
Validation can be done in a loo if he field names are similarly names, which is always a good idea in your kind of scenario.

It can be done in the query save portion.

I'll find some code.

I hope this helps !
0
 
SysExpertCommented:
If felds are s1, s2 s..



In query save
' untested
Dim Nitem As NotesItem, Tstr2 As String
Dim DBE As NotesDocument
Dim ivalue  As Variant , v2 As integer
      Dim Dstr As String, Dstr1 As String, sdt as string
      
      Set dbe=source.Document      
      
      If source.IsNewDoc Then ' do any validation if needed
            
     for v2 = 1 to n  ' n is chosen and saved some where

        Sdt= "S" & v2  'set saved audit field
       Set Nitem = dbe.GetFirstItem( Sdt )
        ' validate here
        If not valid ' do your validation
           Continue = False
        end if
        ' set continue to false if not valid
     next
0
 
SysExpertCommented:
you could also use  source.fieldGetText(SDT)  instead of the GetItem

I hope this helps !

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
cyleAuthor Commented:
Thank you, let me try it!
0
 
marilyngCommented:
Hi cyle,
I usually add a multivalue field to the bottom of the form that lists or computes the fields that need to be validated.  So, in a simple form where I have three fields:  UserName, Address, Phone,  the multivalue field's (labeled validate) calculated value = "UserName":"Address":"Phone".

Then I can use the same validation script in the query close event in just about any form:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Set db = session.currentDatabase
    Dim doc As NotesDocument
    Set doc = source.document
    continue = True
   
    If source.EditMode Then
        source.refresh
    End If
   
    Dim FieldList As Variant
   
    If Len(doc.Validate(0)) > 0 Then
        fieldList = doc.Validate
       
        Forall f In FieldList
            If Len(doc.GetItemValue(f)(0))<1 Then
                Msgbox "Sorry, the " + f + " field may not be blank",,"Validation Error!"
                continue = False
                source.GotoField(f)
                Exit Sub
            End If
        End Forall
    End If
   
End Sub

--------------------------
Based on your problem, you can easily concatenate the formula on your form to include the selected fields:

F1:= @If(Select_1 !="";"UserName";"");
F2:= @If(Select_2 !="";"Address";"");
F3:= @If(Select_3 !="";"Phone";"");

@Trim(F1:F2:F3)


Regards!
0
 
Joep8020Commented:
Easiest way is good all @Formula language:

Let's assume the input field is called InputField and contains a numeric value; then use this formula in the input validation of the input field:
tNr:=@If(@Text(InputField)="";@Return("");InputField);
tList:=@Subset(desc1:desc2: desc3: desc4: desc5: desc6: desc7: desc8: desc9: desc10: desc11: desc12: desc13: desc14: desc15: desc16: desc17: desc18: desc19: desc20;tNr);
@If(@Elements(@Trim(tList))<tNr;@Failure("You need to give at " + @Text(tNR) + " descriptions";@Success);

Hope this will work for you...

0
 
marilyngCommented:
Close!  But, missing a beat.   You would have to define the sets that are visible.

So, if when the user selects "1", desc1,desc2,desc3,desc4 are visible, then you need to validate those four fields.
If when the user selects "2", desc5, desc6, desc7,desc8 are visible, then validate those four fields.

Set1:=desc1:desc2: desc3: desc4;
Set2:=desc5: desc6: desc7: desc8;
Set3:=desc9: desc10: desc11: desc12;
Set4:=desc13: desc14: desc15: desc16;
Set5:=desc17: desc18: desc19: desc20;
REM "User Input is a List that returns a number This Value|1";
UserSelection:=@TextToNumber(UserInput);

@if(UserInput="";@Success;
   @If(
         @Elements(@Trim(@Select(UserSelection;Set1;Set2;Set3;Set4;Set5)))!=
         @Elements(@Select(UserSelection;Set1;Set2;Set3;Set4;Set5));
         @Failure("Sorry, Description fields may not be empty");
@Success))
0
 
marilyngCommented:
Oops, I put a "Validate" field, text, editable, hidden at the bottom of the form, and put the formula in the validation event.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now