1 2 Previous Next 16 Replies Latest reply on May 23, 2016 5:41 AM by m.swanston

    Not Seeing Validation Messages

    m.swanston

      I've added some extra validation to a couple of fields that mirrors working validation, but for reasons unknown to me, the messages aren't being displayed when the validation fails, it just does nothing!

      I'm trying to validate a numeric field to only be a 6 digit value, but if I add a trailing space, it won't let me save, but doesn't display a message stating why either. So here's my field options:

      Auto-Enter tab

      • Calculated value: ticked: Specified calculation: Trim ( Self )

      Validation tab

      • Strict data type: Numeric only;
      • Validated by calculation: Case ( Length ( Self ) ≠ 6; 0; Length ( Filter ( Self; "0123456789" ) ) ≠ 6; 0; 1 )

      Display custom message if validation fails: Please only enter a numeric value.

      auto.png

      valid.png

      calc.png

      If I un-tick the Validated by calculation checkbox, it allows me to save a number of 7 characters, but when appending a letter to the end, the same issue appears, i.e. leaving the layout pops up the 'Save changes to record?' message but when you click Save, nothing happens and no validation message is displayed.

       

      This is also happening to another field, so am hoping that whatever the issue is here, I can apply it to the second field.

       

      Can anyone help me understand why the validation isn't working? I have a similar field (on a different table which uses similar a validation calculation/logic) which works exactly as expected and i can't see any reason why one field works and the other doesn't.

       

      FYI this is happening in both FM Pro Advanced 14 and the application via WebDirect.

       

      Thanks in advance

       

      Martin

        • 1. Re: Not Seeing Validation Messages
          mikebeargie

          Hey Martin,

           

          Validation always takes place before any auto-entry calculation in the order of operations for filemaker. So in essence you're failing your validation with the trailing space before the auto-enter has a chance to even fire.

           

          Since you already have a case condition that checks for a seven digit number (the filter line), removing your first case condition and unchecking the "numeric only" box should be enough.

           

          So change the validation calc to:

          Case ( Length ( Filter ( Self; "0123456789" ) ) ≠ 6; 0 ; 1 )

           

          and update your auto-enter calc to:

           

          Filter ( Self; "0123456789" )

           

          instead of using trim.

           

          Then you should have something that only fails validation in the case of not having seven numbers entered.

           

          FYI, this same type of validation works great for phone number fields, where people might type in 111-111-1111, or 111.111.1111 or (111) 111-1111 and you want to check for a specific number length, then auto-enter a formatted string.

          • 2. Re: Not Seeing Validation Messages
            m.swanston

            Hi Mike

             

            Thanks, that's useful.

             

            I can see where you are going with this, but with the suggested changes, it saves any alpha-numeric values as numeric, without telling the user. If the user enters an alpha-numeric input, I want them to be told what they did wrong, rather than just amend and save their input with any alpha characters stripped out.

             

            The logic behind the trim was to stop users adding spaces to the end (whether in error or intentionally), and then the other validation was set to ensure the user only entered a six digit number. If I revert the code back to Trim for auto-enter but leave the shortened case statement in place (and numeric not ticked), it continues to save and strip out any text...which isn't what happened before?! By re-ticking numeric input, it goes back to how it was working before.

             

            Is there a way to validate and tell the user in all instances except a six digit number?

             

            Thanks again

             

            Martin

            • 3. Re: Not Seeing Validation Messages
              mikebeargie

              That's not true, since you're filtering out anything that's not 0-9, it will work for both validation and auto-entry, in that order. It will not auto-enter anything if it fails validation. And with your filter calculation, alpha characters would be stripped and not counted towards the length.

              • 4. Re: Not Seeing Validation Messages
                m.swanston

                Hi Mike

                I'm not doubting you, but I'm seeing it act exactly as I describe which is not what I'm expecting at all based on what i know and what you've explained above.

                 

                To clarify:

                 

                Strict data type is un-ticked;

                Auto-enter is back at Trim( Self );

                Validation calculation is set to: Case ( Length ( Self ) ≠ 6; 0; Filter ( Self; "0123456789" ) ≠ Self; 0; 1)

                So in my mind, it will save inputs with leading or trailing spaces without the user being told, but should fail validation on alpha-numeric and numbers that are not 6 digits...

                I've checked several times all the settings, exited FM and re-opened but still seeing the same activity.

                Open the Edit layout for this page, enter a value, say 70831X8, then I see the Save changes dialog, so click Save and the view layout is displayed with the value 708318 (the X has been removed).

                Repeat the steps for 708318 with a trailing space, and after clicking Save on the dialog, it trims the value with no issue and returns to the View layout.

                Repeat the steps and enter 7083188, and when I see the Save changes dialog, click save but nothing happens. Only way out is to click Don't save on the changes dialog or put the input back.

                 

                Confused!!

                 

                Thanks

                 

                Martin

                • 5. Re: Not Seeing Validation Messages
                  mikebeargie

                  I am under the impression that since you had the "strict data type: numeric only" dialog checked to begin with, that you only wanted to store numeric values of six characters. Is this not the case?

                   

                  EG these are valid values:

                  123456

                  654321

                   

                  But these are NOT valid values:

                  1234567

                  X123456

                  123X45

                  123XXX

                  _123456 (leading space)

                  123456_ (trailing space)

                   

                  The validation and auto entry calcs I pointed out would fail the first four of those strings, but would automatically compensate for stripping off the errant spaces and validating the last two invalid strings.

                  • 6. Re: Not Seeing Validation Messages
                    m.swanston

                    Hi Mike

                    Yes, that's correct. A bit of history - the application was mostly written by a third party and I now maintain it with help from the third party when required. So I am adding extra validation to fields that already exist, so your info above is useful for future changes.

                    But yes, to confirm am looking to allow users to enter only a six digit number. They should be told via a message if they enter a number that is not six digits or include any alpha characters. I don't want the non-numeric (except leading/trailing space) characters stripped out silently as sometimes the user will enter a value incorrectly that without the alpha element would make no sense - the value may well be used in a billing process, so it's important users know what value they should enter into this field, which is why we want the validation messages rather than silient cleansing.

                    The first two and last two are all valid - the first two are six digit numbers and the last two will be cleansed by the Auto-enter calculation.

                    I hope that makes sense

                    Thanks

                    Martin

                    • 7. Re: Not Seeing Validation Messages
                      mikebeargie

                      Yes, that makes sense,

                       

                      If you want to customize the validation message to fit the situation you are checking for and customize the dialog accordingly, then you might want to switch things around a bit. switching to a script trigger on that field, rather than counting on validation or auto-entry, may be for you.

                       

                      I believe OnObjectValidate would be the proper trigger to use on the field. A script like this would work:

                       

                      If [ length ( filter( table::field ; " " ) ) > 0 ]

                         If [ length ( filter( table::field ; "1234567890" ) ) <> 6 ]

                            Set Variable [ $bad ; filter( table::field ; "abcdefg!@#$% etc..." ) ]

                               if

                                  Show Custom Dialog [ "Error, you have spaces, and alphabetical or special characters in your field, please enter a six digit value only. Bad characters: " & $bad ]

                                  Exit Script

                               Else

                                  Show Custom Dialog [ "Error, you have spaces, and and did not enter six digits, please enter a six digit value only. Bad characters: " & $bad ]

                                  Exit Script

                               End If

                         Else If [ length ( filter( table::field ; "1234567890" ) ) = 6 ]

                            Set Field [ table::field ; filter( table::field ; "1234567890" ) ] //THIS DOES THE SAME AS TRIM...

                            Show Custom Dialog [ "You have spaces in your field, but we took care of it" ]

                         End If

                      Else If [ length ( filter( table::field ; "1234567890" ) ) <> 6 ]

                            Set Variable [ $bad ; filter( table::field ; "abcdefg!@#$% etc..." ) ]

                            Show Custom Dialog [ "Error, you have alphabetical or special characters in your field, please enter a six digit value only. Bad characters: " & $bad ]

                            Exit Script

                      End If

                      Exit Script

                       

                      With that script trigger you could turn off validation and auto-entry in your field and handle everything via a script to the most control and customized error messaging possible.

                      • 8. Re: Not Seeing Validation Messages
                        m.swanston

                        Thanks Mike - that's really helpful, and not something I've done yet (have used script triggers on layout load and buttons but not with regards validation) so thanks for your detailed response.

                        I'll work through the script and have a go at implementing it - will come back if I have any further questions. The second field I mentioned is slightly different, but a similar (less complex) approach to your sugestion above may well be worth me investigating.

                        Thanks again

                        Martin

                        • 9. Re: Not Seeing Validation Messages
                          mikebeargie

                          Sure, one of my current clients need a lot of "if this, then that" validation messages so we switched to trigger validation instead pretty early on. It's the best for "complete" control.

                          • 10. Re: Not Seeing Validation Messages
                            m.swanston

                            Hi Mike

                             

                            Am working through a new script, implementing your suggestion and just have a couple of questions if you don't mind?

                             

                            I don't get why you have used an If without a condition in line 4? I wasn't aware you could do that, and just wanted to be sure it wasn't missing a condition:

                            If [ length ( filter( table::field ; " " ) ) > 0 ]

                               If [ length ( filter( table::field ; "1234567890" ) ) <> 6 ]

                                  Set Variable [ $bad ; filter( table::field ; "abcdefg!@#$% etc..." ) ]

                            ===>  if

                                        Show Custom Dialog...

                             

                            Secondly, have written the script but realised I could re-use the script for other similar numeric only fields, so was thinking of creating a more generic one, but don't know if you can pass in field names as parameters? I'd want to pass in the field name, maximum length of the input and the field description, i.e.
                            CLIENT::d_OracleCode ; 6 ; Client Code

                            Then when I used it for, say a 7 number field called Project Code, I could pass in:

                            SCHEME::d_ProjectCode ; 7 ; Project Code

                            And not have two almost duplicate scripts. Is this doable?

                             

                            Thanks again for your help

                             

                            Regards

                             

                            Martin

                            • 11. Re: Not Seeing Validation Messages
                              erolst

                              You could simplify Mike's example to

                               

                              Set Variable [ $fieldContents ; Get ( ActiveFieldContents ) ]

                              Set Variable [ $fieldLengthFiltered ; Length ( Filter ( $fieldContents ; "1234567890" ) ) ]

                              Set Variable [ $badCharacters ; Length ( Filter ( $fieldContents ; "abcdefg!@#$% etc..." ) ) ]

                              Set Variable [ $errorMessage ;

                              Case (

                                $fieldLengthFiltered <> 6 ;

                                Case (

                                  $badCharacters ;

                                  "Special characters message." ;

                                  "Too many digits message."

                                )

                              )

                              ]

                              If [ Length ( $errorMessage ) ]

                                Show Custom Dialog [ $errorMessage ; … ]

                                Exit Script

                              End If

                               

                              m.swanston wrote:

                              so was thinking of creating a more generic one, but don't know if you can pass in field names as parameters? I'd want to pass in the field name, maximum length of the input and the field description, i.e.

                              CLIENT::d_OracleCode ; 6 ; Client Code

                              Then when I used it for, say a 7 number field called Project Code, I could pass in:

                              SCHEME::d_ProjectCode ; 7 ; Project Code

                              And not have two almost duplicate scripts. Is this doable?

                               

                              You can try this: start your script with

                               

                              Set Variable [ $fieldNameList ; List ( "oracleCode" ; "projectCode" ) ]

                              # [ or use List ( GetValue ( Substitute ( GetFieldName ( field ) ; "::" ; ¶ ) ; 2 ) ; GetValue ( … nextField … // etc. ) to protect against field name changes ]

                              Set Variable [ $maxLengthList ; List ( 6 ; 7 ) ]

                              Set Variable [ $descriptionList ; List ( "desc for OC" ; "desc for PC" ) ]

                              #

                              Set Variable [ $fieldName ; Get ( ActiveFieldName ) ]

                              Set Variable [ $positionInList ;

                              ValueCount ( Left ( $fieldNameList ; Position ( ¶ & $fieldNameList & ¶ ; ¶ & $fieldName & ¶ ; 1 ; 1 ) ) )

                              ]

                               

                              If [ not $positionInList ]

                              Exit Script

                              End If

                               

                              Set Variable [ $fieldContents ; Get ( ActiveFieldContents ) ]

                              Set Variable [ $maxLength ; GetValue ( $maxLengthList ; $positionInList ) ]

                              Set Variable [ $description ; GetValue ( $descriptionList ; $positionInList ) ]

                              # [ code as above, now using these variables ]

                              • 12. Re: Not Seeing Validation Messages
                                m.swanston

                                Thanks erolst - I'll have a play with your code and see how I get on, but it looks exactly what I'm after!

                                Thanks again

                                Martin

                                • 13. Re: Not Seeing Validation Messages
                                  m.swanston

                                  Only one question - is it still possible, with this approach, to replace the input 'silently' without any spaces, ie user enters '123456 ', they don't need to know it is replaced as '123456' - or would the existing auto-enter calculation still be valid?

                                  Thanks

                                  Martin

                                  • 14. Re: Not Seeing Validation Messages
                                    m.swanston

                                    Having implemented this, and also leaving the remaining auto-enter calculation in place, I'm finding it's not working as expected - enter more characters than required, message pops up telling user invalid, user clicks OK and the record saves with the incorrect input. Is the auto-enter calc over-riding the validation script?

                                    Thanks

                                    Martin

                                    1 2 Previous Next