{"record":{"id":"4a777e6f0dbdc78c","repo":"dotnet/aspnetcore","slug":"equalto-validator-requires-a-non-empty-other-par","errorCode":null,"errorMessage":"EqualTo validator requires a non-empty \"other\" parameter.","messagePattern":"EqualTo validator requires a non-empty \"other\" parameter\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Validation/Validators/EqualTo.ts","lineNumber":13,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport { ValidationContext, ValidationResult, Validator, pass, fail } from '../ValidationTypes';\n\n// Validates that the value equals another field's value (for password confirmation, etc.).\n// Resolves \"*.PropertyName\" to the model-prefixed field name using the current field's name.\n// Finds the other field by [name] attribute within the same form.\n// Throws if the mandatory `other` parameter is missing.\nexport const equalToValidator: Validator = (context: ValidationContext): ValidationResult => {\n  const { value, element, params } = context;\n  if (!params.other) {\n    throw new Error('EqualTo validator requires a non-empty \"other\" parameter.');\n  }\n\n  if (!value) {\n    return pass();\n  }\n\n  const otherFieldName = resolveOtherFieldName(element.name, params.other);\n  if (!otherFieldName) {\n    return pass();\n  }\n\n  const form = element.closest('form');\n  if (!form) {\n    return pass();\n  }\n\n  const otherElement = form.querySelector<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(`[name=\"${CSS.escape(otherFieldName)}\"]`);\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Web.JS/src/Validation/Validators/EqualTo.ts#L1-L31","documentation":"The EqualTo validator (used by Blazor's client-side validation for [EqualTo]/compare scenarios, e.g. password confirmation) requires a configuration parameter named 'other' naming the field to compare against. If the rule is registered without that parameter, the validator cannot locate its comparison target and throws immediately rather than silently passing. It runs before any value check so the configuration is validated up front.","triggerScenarios":"Thrown at line 13 when params.other is falsy — i.e. the validator was invoked (e.g. via data-val-equalTo-other attribute or programmatic registration) with no 'other' value supplied.","commonSituations":"A [Compare] / [EqualTo] attribute on the C# model whose client-side data-val-equalTo-other attribute was stripped by tag helpers, a misnamed attribute, or a hand-built form missing the other-field reference; using the validator directly without passing params.","solutions":["Ensure the form field renders the data-val-equalTo-other attribute naming the comparison field (e.g. data-val-equalTo-other=\"*.ConfirmPassword\").","If registering the validator programmatically, pass { other: 'OtherFieldName' } in params.","Check the C# model uses [Compare(nameof(ConfirmPassword))] so tag helpers emit the correct client attribute.","Verify no HTML sanitizer/minifier is stripping data-* attributes."],"exampleFix":"<!-- before -->\n<input name=\"Password\" data-val=\"true\" data-val-equalTo=\"Mismatch\" />\n<!-- after -->\n<input name=\"Password\" data-val=\"true\" data-val-equalTo=\"Passwords do not match\" data-val-equalTo-other=\"*.ConfirmPassword\" />","handlingStrategy":"validation","validationCode":"// Ensure the rule carries its 'other' param before the validator runs\nfunction equalToConfigured(params: any): boolean {\n  return !!params && typeof params.other === 'string' && params.other.length > 0;\n}","typeGuard":"function hasOtherParam(p: unknown): p is { other: string } {\n  return !!p && typeof (p as any).other === 'string' && (p as any).other.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Use [Compare(nameof(Other))] on the model so tag helpers emit data-val-equalTo-other.","Audit rendered inputs to confirm data-val-equalTo-other is present.","Ensure HTML sanitizers do not strip data-* attributes.","When registering validators manually, always pass required params."],"tags":["blazor","validation","equalto","form-validation","misconfiguration"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}