{"record":{"id":"ff61027cee8d028b","repo":"RocketChat/Rocket.Chat","slug":"error-user-registration-custom-field","errorCode":"error-user-registration-custom-field","errorMessage":"Field ${fieldName} is required","messagePattern":"Field (.+?) is required","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/users/validateCustomFields.js","lineNumber":29,"sourceCode":"\t}\n\n\tlet customFieldsMeta;\n\ttry {\n\t\tcustomFieldsMeta = JSON.parse(settings.get('Accounts_CustomFields'));\n\t} catch (e) {\n\t\tthrow new Meteor.Error('error-invalid-customfield-json', 'Invalid JSON for Custom Fields');\n\t}\n\n\tconst customFields = {};\n\n\tObject.keys(customFieldsMeta).forEach((fieldName) => {\n\t\tconst field = customFieldsMeta[fieldName];\n\n\t\tcustomFields[fieldName] = fields[fieldName];\n\t\tconst fieldValue = trim(fields[fieldName]);\n\n\t\tif (field.required && fieldValue === '') {\n\t\t\tthrow new Meteor.Error('error-user-registration-custom-field', `Field ${fieldName} is required`, { method: 'registerUser' });\n\t\t}\n\n\t\tif (field.type === 'select' && field.options.indexOf(fields[fieldName]) === -1) {\n\t\t\tthrow new Meteor.Error('error-user-registration-custom-field', `Value for field ${fieldName} is invalid`, { method: 'registerUser' });\n\t\t}\n\n\t\tif (field.maxLength && fieldValue.length > field.maxLength) {\n\t\t\tthrow new Meteor.Error('error-user-registration-custom-field', `Max length of field ${fieldName} ${field.maxLength}`, {\n\t\t\t\tmethod: 'registerUser',\n\t\t\t});\n\t\t}\n\n\t\tif (field.minLength && fieldValue.length > 0 && fieldValue.length < field.minLength) {\n\t\t\tthrow new Meteor.Error('error-user-registration-custom-field', `Min length of field ${fieldName} ${field.minLength}`, {\n\t\t\t\tmethod: 'registerUser',\n\t\t\t});\n\t\t}\n\t});","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/users/validateCustomFields.js#L11-L47","documentation":"The Accounts_CustomFields definition marks a field required: true, and the submitted fields object carries an empty or whitespace-only value for it (trimmed with trim() before the check). Thrown per field inside the loop at validateCustomFields.js:27-30 with the offending fieldName in the message and { method: 'registerUser' } in details.","triggerScenarios":"Registering or saving a profile that omits a required custom field, submits an empty string, or submits only whitespace for it.","commonSituations":"Client forms that don't mark the custom input as required; fields made mandatory by the admin after the form/UI was built; API registrations written before the field existed.","solutions":["Submit a non-empty value for the field named in the error message","Mark the input required in the client form so validation blocks submit early","If the field should be optional, remove required (or set required: false) in Accounts_CustomFields"],"exampleFix":"// before\nvalidateCustomFields({ department: '' }); // Field department is required\n\n// after\nvalidateCustomFields({ department: 'sales' });","handlingStrategy":"validation","validationCode":"const meta = JSON.parse(settings.get('Accounts_CustomFields'));\nconst missing = Object.entries(meta)\n  .filter(([key, field]) => field.required && String(fields[key] ?? '').trim() === '')\n  .map(([key]) => key);\nif (missing.length) {\n  // block submit and highlight these inputs\n}","typeGuard":null,"tryCatchPattern":"try {\n  validateCustomFields(fields);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-user-registration-custom-field' && /required/i.test(error.reason)) {\n    // flag the field named in the message\n  } else {\n    throw error;\n  }\n}","preventionTips":["Mirror required flags into the form schema when the setting changes","Trim client-side before submit — whitespace does not satisfy required","Re-sync the client form definition whenever Accounts_CustomFields changes"],"tags":["custom-fields","registration","validation","meteor"],"backgroundTag":"custom-field-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}