Skip to content

Commit 32963eb

Browse files
committed
Added docs for InputValidator
1 parent 176ab42 commit 32963eb

2 files changed

Lines changed: 108 additions & 0 deletions

File tree

docs/articles/features/ui-controls-validator.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,111 @@ title: Using the InputValidator control | MADE.NET
55

66
# Using the InputValidator control
77

8+
The `MADE.UI.Controls.InputValidator` element is a custom-built UI element wrapper for input controls that works with [Uno's supported platforms](https://platform.uno/) that provides an input validation experience.
9+
10+
Shown below is the visuals for the control in its default state validating a `TextBox` and `DatePicker` with input validators from the `MADE.NET.Data.Validation` library.
11+
12+
<img src="../../images/InputValidator.png" alt="InputValidator usages for a TextBox and DatePicker" />
13+
14+
## Example usage
15+
16+
```xml
17+
<Page
18+
x:Class="InputValidatorSample.MainPage"
19+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
20+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
21+
xmlns:controls="using:MADE.UI.Controls"
22+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
23+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
24+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
25+
mc:Ignorable="d">
26+
27+
<RelativePanel Padding="12">
28+
<controls:InputValidator
29+
x:Name="TextBoxValidator"
30+
Margin="0,12,0,0"
31+
Input="{x:Bind TextBox.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
32+
RelativePanel.AlignLeftWithPanel="True"
33+
RelativePanel.AlignRightWithPanel="True"
34+
RelativePanel.AlignTopWithPanel="True">
35+
<TextBox x:Name="TextBox" Header="TextBox with InputValidator" />
36+
</controls:InputValidator>
37+
38+
<controls:InputValidator
39+
x:Name="DatePickerValidator"
40+
Margin="0,12,0,0"
41+
Input="{Binding SelectedDate, Mode=TwoWay, ElementName=DatePicker, UpdateSourceTrigger=PropertyChanged}"
42+
RelativePanel.AlignLeftWithPanel="True"
43+
RelativePanel.AlignRightWithPanel="True"
44+
RelativePanel.Below="TextBoxValidator">
45+
<DatePicker x:Name="DatePicker" Header="DatePicker with InputValidator" />
46+
</controls:InputValidator>
47+
</RelativePanel>
48+
</Page>
49+
```
50+
51+
```csharp
52+
namespace InputValidatorSample
53+
{
54+
using System;
55+
using System.Collections.Generic;
56+
using System.Collections.ObjectModel;
57+
using System.Diagnostics;
58+
using global::Windows.UI.Xaml.Controls;
59+
using MADE.Data.Validation;
60+
using MADE.Data.Validation.Validators;
61+
using MADE.UI.Controls;
62+
63+
public sealed partial class MainPage : Page
64+
{
65+
public MainPage()
66+
{
67+
this.InitializeComponent();
68+
69+
this.TextBoxValidator.Validators = new ValidatorCollection
70+
{
71+
new RequiredValidator(),
72+
new EmailValidator(),
73+
};
74+
75+
this.DatePickerValidator.Validators = new ValidatorCollection
76+
{
77+
new RequiredValidator(),
78+
new BetweenValidator(DateTimeOffset.Now, DateTimeOffset.Now.AddDays(7)),
79+
};
80+
}
81+
}
82+
}
83+
```
84+
85+
## Validating an input
86+
87+
The `InputValidator` is designed in a way that it can be used with any input control, whether in-built like `TextBox` or custom-built like the MADE `FilePicker` control.
88+
89+
Simply, the `Input` property of the validator needs to be bound to the input value reference from the wrapped input control that needs to be validated.
90+
91+
You can then provide a `ValidatorCollection` instance from the [Data Validation package](data-validation.md), containing the `IValidator` instances that will be run on the input.
92+
93+
This can either be a bound property in your view-model, set in your view code-behind, or defined in your XAML as a static resource.
94+
95+
The implementation of using `IValidator` instances allows you to dynamically configure your validators based on other criteria of your view.
96+
97+
For example, you might want to validate two `DatePicker` controls that define a min/max range. The validator for the maximum date could be dynamically updated so that its minimum value is defined based on the value of the minimum date picker.
98+
99+
## Extending input validation for your application's needs
100+
101+
The validation of the `InputValidator` is based on `IValidator` instances from the Data Validation package.
102+
103+
While the package provides a common set of validators for basic scenarios such as required, range, min, max, and email, you can create your own.
104+
105+
Find more detail on creating your own custom `IValidator` types in our [Data Validation article](data-validation.md#creating-your-own-custom-data-validators).
106+
107+
## Customizing the InputValidator
108+
109+
The control has many customization properties that are exposed to tailor the experience for your application.
110+
111+
### FeedbackMessageStyle
112+
113+
The `FeedbackMessageStyle` controls the styling applied to the `TextBlock` that displays the validator messages.
114+
115+
The default user experience styling is shown at the top of this article.

docs/images/InputValidator.png

24.6 KB
Loading

0 commit comments

Comments
 (0)