Form validations in appsettings.forms section doesn't seem to work

Hi fellow CHT members,

I created a test form containing the Age field and added length and range validations for it but the code only seems to check for the type of the age field, during the parsing of the message.

Hence the only place to validate these seem to be when running registration triggers by adding validations there.

Was this intended? I believe, as much as possible we should fail fast and fail early. Please kindly advise.

Sample form config below.:

      "NP": {
        	"meta": {
        		"code": "NP",
        		"translation_key": "forms.np.title",
        		"label": {
        			"en": "Just age and name"
        		}
        	},
        	"fields": {
        		"patient_age": {
        			"labels": {
        				"tiny": {
        					"en": "Person Age"
        				},
        				"short": {
        					"en": "Person Age"
        				}
        			},
        			"position": 0,
        			"type": "integer",
        			"length": [
        				1,
        				3
        			],
        			"range": [
        				0,
        				125
        			],
        			"required": true
        		},
        		"patient_name": {
        			"labels": {
        				"tiny": {
        					"en": "patient_name"
        				},
        				"description": {
        					"en": "Patient name"
        				},
        				"short": {
        					"en": "Patient name"
        				}
        			},
        			"position": 1,
        			"type": "string",
        			"length": [
        				3,
        				30
        			],
        			"required": true
        		}
        	},

        	"public_form": false,
        	"use_sentinel": true

        }

Hi @Prajwol

You are correct, we validate the existence and type of the field when the message is created and only run full validations for transitions. The range property doesn’t get checked for, please have a look at the field properties that are checked: .forms | Community Health Toolkit
From what I can tell, the length property isn’t validated either.

1 Like

Thanks @diana. Probably should cleanup settings where we have these in our projects.