I am following the Forms docs. The following example does not give me the promised result
class ValidationContextDemo : Component
{
public override Element Render()
{
var ctx = this.UseValidationContext();
var (email, setEmail) = UseState("");
var (password, setPassword) = UseState("");
var (submitted, setSubmitted) = UseState(false);
return VStack(12,
SubHeading("Validation Context"),
TextBox(email, v => { setEmail(v); ctx.NotifyValueChanged("email", v); },
placeholderText: "user@example.com", header: "Email")
.Validate("email", email,
Validate.Required(),
Validate.Email()),
When(ctx.IsTouched("email") && ctx.HasError("email"), () =>
TextBlock(ctx.GetMessages("email").First().Text)
.Foreground(Theme.SystemCritical).FontSize(12)),
PasswordBox(password, v => { setPassword(v); ctx.NotifyValueChanged("password", v); },
placeholderText: "Min 8 characters")
.Header("Password")
.Validate("password", password,
Validate.Required(),
Validate.MinLength(8)),
When(ctx.IsTouched("password") && ctx.HasError("password"), () =>
TextBlock(ctx.GetMessages("password").First().Text)
.Foreground(Theme.SystemCritical).FontSize(12)),
Button("Register", () =>
{
ctx.MarkAllTouched();
System.Diagnostics.Debug.WriteLine(
$"email errors: {ctx.GetMessages("email").Count()}, " +
$"password errors: {ctx.GetMessages("password").Count()}, " +
$"valid: {ctx.IsValid()}");
if (ctx.IsValid()) setSubmitted(true);
}).IsEnabled(!submitted),
When(submitted, () =>
TextBlock("Registration successful!")
.Foreground(Theme.SystemSuccess).SemiBold())
).Padding(24)
.RequestedTheme(ElementTheme.Light)
.Backdrop(BackdropKind.Mica);
}
}
When I click the "Register" button, the form gets submitted successfully without any error.
What happened?
I am following the Forms docs. The following example does not give me the promised result
https://microsoft.github.io/microsoft-ui-reactor/latest/forms/#validation-context
example code:
When I click the "Register" button, the form gets submitted successfully without any error.
Steps to reproduce
Reactor version / commit
0.1.0-preview.15
Platform
x64
.NET SDK version
10.0.401
Windows version
Windows 11 25H2 (26200.9457)
Windows App SDK version
2.5.1
Logs / stack trace
Confirmation
mainbranch (or I've noted otherwise above).