Field Validation
Description
We can have custom validations written in javascript for Registration Fields.
For achieving this, need to do the following
- Add a file called fieldValidation.js and put it under "/var/www/bahmni_config/openmrs/apps/registration/" directory.
- Add the functions required to validate the field.
- Include fieldValidation.js in bahmniapps/registration/index.html.
The format of the validator should be like below
Config
"<field id>" : {
method: function (name, value, attributeDetails) {
if (.......) {
return true;
}
return false;
},
errorMessage: "Error Message"
}
};The fieldName details can be obtained from the openmrs administration module (Patient Attributes). The validators will work for non-attributes as well. For non attributes, you will need to get the field names using some html debuggers.
Patient Name Related Custom Field Validation Configurations
If the format of the patient names need to be changed, the global property patient.nameValidationRegex needs to be updated. This field is used in server side validations by openmrs.
The attribute details contain the below fields,
| Property | Description |
|---|---|
| description | Its a description |
| format | java class of the attribute |
| name | name of the attribute |
| uuid | uuid of the attribute |
Example Fields:
Code Snippet
Bahmni.Registration.customValidator = {
"age.days": {
method: function (name, value) {
return value >= 0;
},
errorMessage: "REGISTRATION_AGE_ERROR_KEY"
},
"Telephone Number": {
method: function (name, value, personAttributeDetails) {
return value && value.length> 6;
},
errorMessage: "REGISTRATION_TELEPHONE_NUMBER_ERROR_KEY"
},
"caste": {
method: function (name, value, personAttributeDetails) {
return value.match(/^\w+$/);
},
errorMessage: "REGISTRATION_CASTE_TEXT_ERROR_KEY"
}
};원문 정보
원문 보기 ↗Bahmni Wiki · CC BY-SA 4.0