Announcement

Collapse
No announcement yet.

How to disable back end field validation to avoid the "Field Validation" error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to disable back end field validation to avoid the "Field Validation" error

    Sometimes, for whatever reason, it is preferred to bypass Espo's built in field validation rules to avoid triggering the "Field Validation Error" message and interrupting the back end program flow.

    Fortunately, this is now possible using metadata settings, so it is not necessary to do any coding to accomplish this.

    Simply add these two parameters in your custom entity entityDefs json file under the field for which you want to bypass all validations:

    Code:
    "validationList": [],
    "mandatoryValidationList": []​

    For participants that do not mind writing code, the documentation https://docs.espocrm.com/development...validationlist has information on how to define and invoke custom back end validations in case this is the preferred solution.

  • #2
    thanks for sharing.
    Rabii
    Web Dev

    Comment


    • telecastg
      telecastg commented
      Editing a comment
      You're very welcome rabii

  • #3
    telecastg
    I tried to use this code for one field, but I get a json error (wrong code). It might be because of the [ ]. Has there to be any value? Or just leaving the brackets?
    Thank you in advance.

    Comment


    • shalmaxb
      shalmaxb commented
      Editing a comment
      Thank you, then that is, why it does not work here, my client uses 7.3.2. Will recommend to him to update and then try again.

    • telecastg
      telecastg commented
      Editing a comment
      If it doesn't work, try checking the entitDefs custom script with your development platform/ editor to see if it detects any json structure errors. I use Eclipse from Apache and it will highlight json structure errors.


      Another option (just for you friend, because you always help everyone), post the code from 'custom/Espo/Custom/Resources/metadata/entityDefs/Quote.json' and I will take a look too.

    • telecastg
      telecastg commented
      Editing a comment
      I I see the same red dot in shalmaxb code when I run it through https://jsonlint.com/ as item suggested, and it throws an error, but if I simply remove the red dot it works fine.

      I suggest trying that and then copy and paste the "clean" code into your json file

  • #4
    Hi,
    thank you for your offer telecastg.
    Here is the field, that needs to bypass the validation:

    Code:
    "shippingCost": {
    "tooltip": true,
    "default": 10,
    "onlyDefaultCurrency": false,
    "conversionDisabled": false,
    "validationList": [],
    "mandatoryValidationList": []​
    },​
    but still on rebuild I get a json code error, which is not there, when I rebuild without the two lines. Version espoCRM is now 7.3.4

    Comment


    • #5
      special caractere at the end !

      Comment


      • telecastg
        telecastg commented
        Editing a comment
        Is that the red dot item ? How did you find it ?

        I checked shalmaxb posted code with Notepad++ and could not reproduce the error

        I also checked on my installation and I have an entityDefs file like this, working without any problems

        "startingDate": {
        "type": "datetime",
        "validationList": [],
        "mandatoryValidationList": []
        },
        "endingDate": {
        "type": "datetime",
        "validationList": [],
        "mandatoryValidationList": []
        },
        "firstExecutionDate": {
        "type": "datetime",
        "validationList": [],
        "mandatoryValidationList": []
        },
        Last edited by telecastg; 03-12-2023, 05:11 AM.

      • item
        item commented
        Editing a comment
        Hello @telecastg
        Yes red point

        JSONLint is the free online validator, json formatter, and json beautifier tool for JSON, a lightweight data-interchange format. You can format json, validate json, with a quick and easy copy+paste.


        I have just add 2 braket and copy/past the code between braket

        Results

        Error: Parse error on line 8:
        ...yValidationList": []​ }}
        -----------------------^
        Expecting 'EOF', '}', ',', ']', got 'undefined'

        My experiment, each time you have error json and not see nothing anything, the json have special encoding bad caractère

        You then do not copy/past but write manually the 2 lines
        Last edited by item; 03-12-2023, 10:38 AM.

    • #6
      i have just copy past .. in "sublime text" editor :
      i don't know what's is "​​​<0x200b>" .. it's maybe invaders ..

      Comment


      • #7
        item and telecastg

        Great! That did it. The shown characters, which are not visible in the editor I use (Notepad++) is the so called "zero width space" (I think the 0x200b ist the HEX code for that character). In another discussion I found the reason: This character is inserted by Google Chrome (don`t know if in other browsers too) and you see them as soon as you open the browser tools pointing to the code inserted in the first thread, see photo.
        As soon as I typed the code instead of copying, it worked.
        Thank you for your efforts and hints!

        Comment


        • #8
          I had the same issue Upgrading to 7.3.4, this solved my issue, as we probably had some misadjustment from the people that developed the site we use for the payments, but the update really meant that for 3 days until we noticed, no payments were being registered into the system, because the policy of field validation changed.

          I had the same issue too when copying the solution, it added an extra character, but thanks to that you posted the solution here it was solved quickly too.

          Thank you all!

          Comment


          • #9
            Hi telecastg

            i have a question for you :
            i have create a custom entityDefs reminder.json
            PHP Code:
            {
                
            "fields": {
                    
            "type": {
                      
            "type""enum",
                        
            "options": [
                            
            "__APPEND__",
                            
            "Sms"
                        
            ]
                    }
                }
            }
            ​ 
            I see Sms in reminder->type... but validation issue.
            Error 400: Bad request
            Backend validation failure.

            Field: reminders
            Validation: valid


            I have seach but it's hard code TYPE_EMAIL, TYPE_EMAIL on field Validator.
            Where do i have put for disable validator and create my own field validator who are just a copy past out-of-box validator and add 'Sms'

            Thanks

            Comment


            • telecastg
              telecastg commented
              Editing a comment
              Hello @item

              Easiest solution is to write this:

              {
              "fields": {
              "type": {
              "type": "enum",
              "options": [
              "__APPEND__",
              "Sms"
              ],
              "validationList": [],
              "mandatoryValidationList": []
              }
              }
              }

              The above will tell the system to ignore the hard coded validation rules.

          • #10
            Hi Telecastg,

            found-it
            As reminder is a entity.. so this work in entityDefs meeting.json
            I have leave out-of-box validatorMaxCount, i will copy-past the other valid in custom folder.

            PHP Code:
            {
                
            "fields": {
                    
            "reminders": {
                        
            "validatorClassNameList": [
                            
            "Espo\\Modules\\Crm\\Classes\\FieldValidators\\Event\\Reminders\\MaxCount"
                        
            ]
                    },
            ​ 
            And in entityDefs reminder.jon :

            PHP Code:
            {
                
            "fields": {
                    
            "type": {
                        
            "options": [
                            
            "__APPEND__",
                            
            "Sms"
                        
            ]
                    }
                }
            }
            ​ 
            Regards

            Comment

            Working...
            X