lib/impl/refactorRules.js
function isFieldStillValidTarget(fieldOrPageIdToCheck, pages, cb) {
      var fieldExistsInForm = false;
      var invalidPages = _.filter(pages, function(page) {
        var currentPageId = page._id.toString();

        if (currentPageId === fieldOrPageIdToCheck) {
          fieldExistsInForm = true;
        }
        var invalidFieldList = _.filter(page.fields, function(field) {
          var currentFieldId = field._id.toString();
          if (currentFieldId === fieldOrPageIdToCheck) {
            //Current field exists
            fieldExistsInForm = true;

            //Field is admin only, therefore it is an invalid target for a rule.
            if (field.adminOnly) {
              return true;
            } else {
              return false;
            }
          } else {
            return false;
          }
        });

        //If the invalidFieldList is > 0, it means that one of the fields was invalid.
        return invalidFieldList.length > 0;
      });

      var invalidField = invalidPages.length > 0;

      //Invalid if either the field is invalid, or it does not exist in the form.
      if (invalidField === true || !fieldExistsInForm) {
        return cb(true);
      } else {
        return cb();
      }
    }
function isFieldStillValidTarget(fieldOrPageIdToCheck, pages, cb) {
      var fieldExistsInForm = false;
      var invalidPages = _.filter(pages, function(page) {
        var currentPageId = page._id.toString();

        if (currentPageId === fieldOrPageIdToCheck) {
          fieldExistsInForm = true;
        }
        var invalidFieldList = _.filter(page.fields, function(field) {
          var currentFieldId = field._id.toString();
          if (currentFieldId === fieldOrPageIdToCheck) {
            //Current field exists
            fieldExistsInForm = true;

            //Field is admin only, therefore it is an invalid target for a rule.
            if (field.adminOnly) {
              return true;
            } else {
              return false;
            }
          } else {
            return false;
          }
        });

        //If the invalidFieldList is > 0, it means that one of the fields was invalid.
        return invalidFieldList.length > 0;
      });

      var invalidField = invalidPages.length > 0;

      //Invalid if either the field is invalid, or it does not exist in the form.
      if (invalidField === true || !fieldExistsInForm) {
        return cb(true);
      } else {
        return cb();
      }
    }
function isFieldStillValidTarget ( fieldOrPageIdToCheck , pages , cb ) { var fieldExistsInForm = false ; var invalidPages = _ . filter ( pages , function ( page ) { var currentPageId = page . _id . toString ( ) ; if ( currentPageId === fieldOrPageIdToCheck ) { fieldExistsInForm = true ; } var invalidFieldList = _ . filter ( page . fields , function ( field ) { var currentFieldId = field . _id . toString ( ) ; if ( currentFieldId === fieldOrPageIdToCheck ) { //Current field exists fieldExistsInForm = true ; //Field is admin only, therefore it is an invalid target for a rule. if ( field . adminOnly ) { return true ; } else { return false ; } } else { return false ; } } ) ; //If the invalidFieldList is > 0, it means that one of the fields was invalid. return invalidFieldList . length > 0 ; } ) ; var invalidField = invalidPages . length > 0 ; //Invalid if either the field is invalid, or it does not exist in the form. if ( invalidField === true || ! fieldExistsInForm ) { return cb ( true ) ; } else { return cb ( ) ; } }
A field target is not valid if it does not exist in the form or it is an adminOnly field.
@param fieldOrPageIdToCheck
@param pages
@returns {boolean}
A field target is not valid if it does not exist in the form or it is an adminOnly field .