lib/impl/updateForm.js
function validatefieldCodes() {
    //Flag for finding a duplicate field code
    var duplicateFieldCode = false;
    var invalidFieldCode = false;
    var fieldCodes = {};

    formData.pages = _.map(formData.pages, function(page) {
      page.fields = _.map(page.fields, function(field) {
        var fieldCode = field.fieldCode;

        //If not set, then just return the field.
        if (fieldCode === null || typeof(fieldCode) === "undefined") {
          return field;
        }

        //Checking for duplicate field code. It must be a string.
        if (typeof(fieldCode) === "string") {
          //If the length of the code is 0, then don't save it.
          if (fieldCode.length === 0) {
            delete field.fieldCode;
          } else {
            //Checking for duplicate field code
            if (fieldCodes[fieldCode]) {
              duplicateFieldCode = true;  //Flagging the field as duplicate
            } else {
              fieldCodes[fieldCode] = true;
            }
          }
        } else {
          invalidFieldCode = true; //Field codes must be a string.
        }

        return field;
      });

      return page;
    });

    if (duplicateFieldCode) {
      return new Error("Duplicate Field Codes Detected. Field Codes Must Be Unique In A Form.");
    }

    if (invalidFieldCode) {
      return new Error("Invalid Field Code. Field Codes Must Be A String.");
    }

    //All valid. can proceed to saving the form.
    return undefined;
  }
function validatefieldCodes() {
    //Flag for finding a duplicate field code
    var duplicateFieldCode = false;
    var invalidFieldCode = false;
    var fieldCodes = {};

    formData.pages = _.map(formData.pages, function(page) {
      page.fields = _.map(page.fields, function(field) {
        var fieldCode = field.fieldCode;

        //If not set, then just return the field.
        if (fieldCode === null || typeof(fieldCode) === "undefined") {
          return field;
        }

        //Checking for duplicate field code. It must be a string.
        if (typeof(fieldCode) === "string") {
          //If the length of the code is 0, then don't save it.
          if (fieldCode.length === 0) {
            delete field.fieldCode;
          } else {
            //Checking for duplicate field code
            if (fieldCodes[fieldCode]) {
              duplicateFieldCode = true;  //Flagging the field as duplicate
            } else {
              fieldCodes[fieldCode] = true;
            }
          }
        } else {
          invalidFieldCode = true; //Field codes must be a string.
        }

        return field;
      });

      return page;
    });

    if (duplicateFieldCode) {
      return new Error("Duplicate Field Codes Detected. Field Codes Must Be Unique In A Form.");
    }

    if (invalidFieldCode) {
      return new Error("Invalid Field Code. Field Codes Must Be A String.");
    }

    //All valid. can proceed to saving the form.
    return undefined;
  }
function validatefieldCodes ( ) { //Flag for finding a duplicate field code var duplicateFieldCode = false ; var invalidFieldCode = false ; var fieldCodes = { } ; formData . pages = _ . map ( formData . pages , function ( page ) { page . fields = _ . map ( page . fields , function ( field ) { var fieldCode = field . fieldCode ; //If not set, then just return the field. if ( fieldCode === null || typeof ( fieldCode ) === "undefined" ) { return field ; } //Checking for duplicate field code. It must be a string. if ( typeof ( fieldCode ) === "string" ) { //If the length of the code is 0, then don't save it. if ( fieldCode . length === 0 ) { delete field . fieldCode ; } else { //Checking for duplicate field code if ( fieldCodes [ fieldCode ] ) { duplicateFieldCode = true ; //Flagging the field as duplicate } else { fieldCodes [ fieldCode ] = true ; } } } else { invalidFieldCode = true ; //Field codes must be a string. } return field ; } ) ; return page ; } ) ; if ( duplicateFieldCode ) { return new Error ( "Duplicate Field Codes Detected. Field Codes Must Be Unique In A Form." ) ; } if ( invalidFieldCode ) { return new Error ( "Invalid Field Code. Field Codes Must Be A String." ) ; } //All valid. can proceed to saving the form. return undefined ; }
User Field codes must be unique within a form.

All field codes must have a length > 0, otherwise don't save the form.

No asynchronous functionality in this function.
@param cb
User Field codes must be unique within a form .