Registration Form
A complete mobile-style registration flow with input validation and shake feedback on errors.
Overview
This example demonstrates a complete mobile-style registration flow built entirely from package controls. It shows how styled input fields, a multi-option selector, a gradient submit button, and shake-based validation feedback can be composed into a cohesive form screen.
Controls Featured
- PillInputField — pill-shaped single-line input used for Name, Email, and Password fields
- RoundedInputField — rounded multiline input used for the Bio field
- PillButton — gradient-styled pill button used as the Submit action
- PillSelector — horizontally scrollable option selector used for the Category field; tapping cycles through available options
- VisualElementShakeUtility — plays a horizontal shake animation on any
VisualElement; triggered on invalid fields at submit time
Scene Setup
- Create a new Unity scene.
- Add an empty GameObject named
RegistrationFormDemoto the scene hierarchy. - Add a
UIDocumentcomponent to the GameObject. - Create a
PanelSettingsasset (Assets > Create > UI Toolkit > Panel Settings) and configure it:- Scale Mode: Scale With Screen Size
- Reference Resolution: 1080 × 1920
- Screen Match Mode: Match Width Or Height, blended toward Height
- Assign the
PanelSettingsasset to theUIDocumentcomponent’s Panel Settings field. - Add the
RegistrationFormDemoMonoBehaviour (found inExamples~/RegistrationForm/) to the same GameObject. - Press Play.
What to Expect
The form presents the following fields from top to bottom:
| Field | Control | Notes |
|---|---|---|
| Name | PillInputField |
Single-line, required |
PillInputField |
Single-line, validated against email regex | |
| Password | PillInputField |
Single-line, obscured |
| Bio | RoundedInputField |
Multiline, optional |
| Category | PillSelector |
Tap to cycle options (e.g., Creator, Developer, Designer …) |
Tapping Submit (PillButton with gradient background) triggers validation:
- Any required field that is empty or contains an invalid value plays the
VisualElementShakeUtilityshake animation and its label turns red. - When all fields pass validation the form transitions to a success state: the fields are hidden and a confirmation message is displayed.
Key Code Patterns
Applying a shake animation to an invalid field and marking it red:
private void ValidateAndSubmit()
{
bool isValid = true;
if (string.IsNullOrWhiteSpace(_nameField.Value))
{
VisualElementShakeUtility.Shake(_nameField);
isValid = false;
}
// Validate email format against the @ regex
string emailPattern = @"^[^@\s]+@[^@\s]+\.[^@\s]+$";
if (!System.Text.RegularExpressions.Regex.IsMatch(_emailField.Value, emailPattern))
{
VisualElementShakeUtility.Shake(_emailField);
isValid = false;
}
if (isValid)
{
ShowSuccessState();
}
}