Start a conversation

Check if all fields are complete (and list empty fields)

With this calculation template, you can check whether a group of fields have been filled in or are empty. If certain fields are not filled in, they will be listed in the calculation. In this example, the fields "Gender", "Year of Birth" and "Pregnancy" are checked. Replace the field labels and variable names in the second and third line of the calculation, respectively, with your own labels and variable names. 

Please note that this calculation might not work well with multiline text fields in which new lines ("Enters") are used.

'##allowempty##';
var req_labels = ["Gender", "Year of Birth", "Pregnancy"];
var req_fields = ["{gender}", "{year_birth}", "{pregnant}"];
var incomplete = false;
var missingVars = "";
req_fields.forEach(checkCompleteness);if(incomplete === true){
    "Fields are missing: " + missingVars;
}else{
   "Yes";
} function checkCompleteness(value, index, array) {
  console.log(value);
  if(value ==  "'NA'" ){ 
      incomplete = true;
      missingVars  += req_labels[index];
      missingVars  += ", ";
  }
}


You can also add a validation message that is triggered when not all of the fields are filled in.


The calculation and validation message will look like this in the data entry:

Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Castor Support Team

  2. Posted
  3. Updated