Search code examples
lotus-noteslotus-domino

Making a valdiation for a numeric field


MIght be a silly question but i've been stuck with the following problem:

So I have field "svars" which is number field. What I want to achieve is that when a user enters value that's equal to 0, it sets shows a prompt and sets the value to "". I know that the "" after the @prompt won't do that but I can't figure out how to make that happen, because the action of the condition in @if is the prompt and it sets the value to 1 all the time if i press OK in the prompt box. Anyone have any suggestions how to do the check, set the value to "" and display a prompt?

@If (svars=0; 
        @Prompt([OK];"Kļūda";"Kļūdas teksts");
    ""
    )

Solution

  • There are two places that you need to take into consideration. The first is the "Input Translation" of the field. There you usally do changes in the field. If you would like to reset 0 to "" then you could write the following code in the translation formula:

    @If( @ThisValue = 0; 
         @Do( @Prompt( [OK] ; "Kļūda";"Kļūdas teksts"); "" );
         @ThisValue );
    

    The formula shows a prompt and then replaces the fieldvalue with "" for value = 0, otherwise keeps the current value.

    If you want to prohibit saving a document in case of a wrong value, then you use the "Input Validation" formula of the field and could do something like this:

    @If( @ThisValue = 0; 
         @Failure( "Kļūdas teksts" );
         @Success );
    

    This would not reset the "wrong" value, but it would not let the user save the document, until he filled out another value.

    If your "check" is somewhere else (in a Save- Button, or some kind of event), then it would look like this:

    @If( svars = 0; 
         @Do( @Prompt( [OK] ; "Kļūda";"Kļūdas teksts"); FIELD svars := ""  );
         "" );
    

    This is the most insecure way to do it, because a user can always save a document without pressing your button just by using "Ctrl + S" or the disk- symbol