Custom Validator - Custom Error Message

Hi! Thank you again for this amazing tool.
Is there a chance in the future that the CustomValidator could return a "Custom Error Message"?

i.e.
(bool, string) ValidateSomething(string someFieldValue)
{
string errorMesg = "";
bool isValid = true;

if (<condition 1>)
{
   errorMsg = "This value must exists in that table"; 
   isValid = false;
} else if (<condition 2>) 
   errorMsg = "This value is duplicated"; 
   isValid = false;
}
// and so on

return (isValid, errorMsg); 

}

Thank you again

I have the same needs hope see that in the future

<RadzenCustomValidator Component="Email" Validator="@(() => ValidateNewEmail(model.Email))" Text=@MessageVariable />
You can try assigning Text property of the validator content to a string variable and assign value to that variable based on your condition.

1 Like

I'm confused about how the variable scoping works for this "@MessageVariable" example. The function "ValidateNewEmail()" somehow has to set an external variable that's in the scope of the Razor markup, but how to do that baffles me. I'd like to request clarification. Thank You.