true-perfect-code
Version: 1.1.87

P11Input Component

The P11Input component is a versatile wrapper around the native HTML <input> element. It provides structured handling for labels, descriptions, and two-way data binding, supporting various input types and culture-specific formatting.
Note: This component abstracts common input functionalities, making it easier to integrate standard text, number, email, or password inputs with Blazor's binding and validation systems.


P11Input Component Examples

These examples demonstrate various configurations and functionalities of the P11Input component, showcasing its flexibility for different input types, binding scenarios, and additional features.

1. Standard Text Input

A basic text input field with a floating label

Put text

Display error message (e.g. wrong user input)

* Username is required

A basic text input field with a label and a descriptive text.

Please enter your full name.

A basic text input field with a label, descriptive text and user error message.

* Your full name is required
Please enter your full name.

Current Value 1: ""

Current Value 2: ""

Current Value 3: "Hello World"

Current Value 4: ""

Implementation

<h4 class="mb-3">1. Standard Text Input</h4>

<p>A basic text input field with a floating label</p>
<P11Input TValue="string"
          @bind-Value="textValue"
          Label="Name"
          UseFloatingLabel="true" 
          Description="Put text" />

<hr />

<p>Display error message (e.g. wrong user input)</p>
<P11Input TValue="string"
          @bind-Value="textValue2"
          Label="Name"
          UseFloatingLabel="true"
          DisplayErrorMessage="* Username is required" />

<hr />

<p>A basic text input field with a label and a descriptive text.</p>
<P11Input Label="Your Name"
          @bind-Value="textValue3"
          Description="Please enter your full name."
          InputType="text" />

<hr />

<p>A basic text input field with a label, descriptive text and user error message.</p>
<P11Input Label="Your Name"
          @bind-Value="textValue4"
          Description="Please enter your full name."
          InputType="text"
          DisplayErrorMessage="* Your full name is required" />

<br />
<p>Current Value 1: "@textValue"</p>
<p>Current Value 2: "@textValue2"</p>
<p>Current Value 3: "@textValue3"</p>
<p>Current Value 4: "@textValue4"</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? textValue = "";
    private string? textValue2 = "";
    private string? textValue3 = "Hello World";
    private string? textValue4 = "";
}


2. Explicit Value Change Logging

This example demonstrates how to explicitly log value changes using the OnChange event. The log below will update when you finish typing and leave the input field.

Type something and then click outside the input field.

Current Logged Value: "Initial Logged Text"


2.1 Check when the key is pressed if Enter, Tab, Escape etc...

This example demonstrates how to hanlde if key is pressed using the OnKeyDown event. The log below will update when you press Enter, Tab etc...

Type something and then click outside the input field.

Current Logged Value: ""

Event Log

This log displays events triggered by the input components, such as focus, blur, and explicit value changes.

Implementation

<h4 class="mb-3">2. Explicit Value Change Logging</h4>
<p>This example demonstrates how to explicitly log value changes using the <code>OnChange</code> event. The log below will update when you finish typing and leave the input field.</p>
<P11Input Label="Log Value Changes"
          @bind-Value="loggedTextValue"
          Description="Type something and then click outside the input field."
          InputType="text"
          OnChange="@((e) => LogEventInput($"Value changed to: '{e.Value}'"))" />
<p>Current Logged Value: "@loggedTextValue"</p>

<hr />

<h4 class="mb-3">2.1 Check when the key is pressed if Enter, Tab, Escape etc...</h4>
<p>This example demonstrates how to hanlde if key is pressed using the <code>OnKeyDown</code> event. The log below will update when you press Enter, Tab etc...</p>
<P11Input Label="Log Value Changes"
          @bind-Value="loggedTextValueKey"
          Description="Type something and then click outside the input field."
          InputType="text"
          OnKeyDown="HandleOnKeyDown" />
<p>Current Logged Value: "@loggedTextValueKey"</p>

@* Event Log *@
<div class="bg-light p-4 rounded mb-4">
    <h4 class="mb-3">Event Log</h4>
    <p>This log displays events triggered by the input components, such as focus, blur, and explicit value changes.</p>
    <div class="border p-2" style="height: 150px; overflow-y: scroll; background-color: #f8f9fa;">
        @foreach (var logEntry in eventLogInput)
        {
            <div>@logEntry</div>
        }
    </div>
</div>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? loggedTextValue = "Initial Logged Text"; // New state for explicit logging example
    private string? loggedTextValueKey = "Initial Logged Text"; // New state for explicit logging example

    private List<string> eventLogInput = new List<string>();

    private void LogEventInput(string message)
    {
        eventLogInput.Add($"{DateTime.Now:HH:mm:ss} - {message}");
        if (eventLogInput.Count > 10)
        {
            eventLogInput.RemoveAt(0);
        }
        StateHasChanged();
    }

    private void HandleOnKeyDown(KeyboardEventArgs e)
    {
        if (e.Key == "Enter")
        {
            // Enter-Logik
            loggedTextValueKey = "ENTER";
        }
        else if (e.Key == "Escape")
        {
            // Escape-Logik
            loggedTextValueKey = "ESC";
        }
        else if (e.Key == "Tab")
        {
            // Tab-Logik
            loggedTextValueKey = "TAB";
        }
        // etc.
    }
}


3. Numeric Input (Integer)

Input field for integer values. Uses CultureInfo.InvariantCulture for consistent parsing.

Enter your age as a whole number.

Current Value: 123

Implementation

<h4 class="mb-3">3. Numeric Input (Integer)</h4>
<p>Input field for integer values. Uses <code>CultureInfo.InvariantCulture</code> for consistent parsing.</p>
<P11Input Label="Age"
          @bind-Value="intValue"
          Description="Enter your age as a whole number."
          InputType="number"
          Culture="@CultureInfo.InvariantCulture" /> @* Using InvariantCulture for consistent number parsing *@
<p>Current Value: @(intValue.HasValue? intValue.ToString() : "null")</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private int? intValue = 123;
}


4. Numeric Input (Decimal / Double)

Input field for decimal values. Demonstrates culture-specific formatting (e.g., comma as decimal separator for German culture).

Enter a price with decimal places (e.g., 12.34 or 12,34 depending on culture).

Current Value: 45,67

Input field for decimal values. Demonstrates culture-specific formatting (e.g., comma as decimal separator for German culture) and validation.

Enter a price with decimal places (e.g., 12.34 or 12,34 depending on culture).

Current Value: 0

Implementation

<h4 class="mb-3">4. Numeric Input (Decimal / Double)</h4>
<p>Input field for decimal values. Demonstrates culture-specific formatting (e.g., comma as decimal separator for German culture).</p>
<P11Input Label="Price"
          @bind-Value="decimalValue"
          Description="Enter a price with decimal places (e.g., 12.34 or 12,34 depending on culture)."
          InputType="text"
          Culture="@germanCulture" />
<p>Current Value: @(decimalValue.HasValue? decimalValue.Value.ToString(germanCulture) : "null")</p>

<EditForm Model="@myTestModel">
    <DataAnnotationsValidator /> @* Wichtig: Aktiviert die Validierung basierend auf DataAnnotations *@
    <p>Input field for decimal values. Demonstrates culture-specific formatting (e.g., comma as decimal separator for German culture) and validation.</p>
    <P11Input Label="Price"
              @bind-Value="myTestModel.TestDecimalValue"
              Description="Enter a price with decimal places (e.g., 12.34 or 12,34 depending on culture)."
              InputType="text"
              Culture="@germanCulture"
              ValidationFor="@(() => myTestModel.TestDecimalValue)" /> @* HIER wird auf die Eigenschaft des Modells verwiesen *@
    <ValidationMessage For="@(() => myTestModel.TestDecimalValue)" /> @* Zeigt den spezifischen Fehler für dieses Feld an *@
    <p>Current Value: @(myTestModel.TestDecimalValue.ToString(germanCulture))</p>
</EditForm>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private decimal? decimalValue = 45.67m;
    private CultureInfo germanCulture = new CultureInfo("de-DE");

    public class MyTestModel
    {
        // Die Eigenschaft, die Sie binden und validieren möchten
        public decimal TestDecimalValue { get; set; }
    }
    private MyTestModel myTestModel = new MyTestModel { TestDecimalValue = 0m };
}


5. Email Input

Input field specifically for email addresses, leveraging the browser's native email validation where available.

Your email address.

Current Value: "test@example.com"

Implementation

<h4 class="mb-3">5. Email Input</h4>
<p>Input field specifically for email addresses, leveraging the browser's native email validation where available.</p>
<P11Input Label="E-Mail"
          @bind-Value="emailValue"
          Description="Your email address."
          InputType="email" />
<p>Current Value: "@emailValue"</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? emailValue = "test@example.com";
}


6. Password Input

Input field for sensitive information like passwords. Characters are masked.

Minimum 8 characters.

Current Value (not displayed for security reasons): [*****]

Implementation

<h4 class="mb-3">6. Password Input</h4>
<p>Input field for sensitive information like passwords. Characters are masked.</p>
<P11Input Label="Password"
          @bind-Value="passwordValue"
          Description="Minimum 8 characters."
          InputType="password" />
<p>Current Value (not displayed for security reasons): [*****]</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? passwordValue = "secure123";
}


7. Input with Additional Attributes & Custom Class

Demonstrates passing arbitrary HTML attributes (like placeholder, maxlength, class) directly to the underlying <input> element, and applying a custom CSS class to the component's root div.

Current Value: "Focus here"

Event Log

This log displays events triggered by the input components, such as focus, blur, and explicit value changes.

Implementation

<h4 class="mb-3">7. Input with Additional Attributes & Custom Class</h4>
<p>Demonstrates passing arbitrary HTML attributes (like <code>placeholder</code>, <code>maxlength</code>, <code>class</code>) directly to the underlying <code>&lt;input&gt;</code> element, and applying a custom CSS class to the component's root <code>div</code>.</p>
<P11Input Label="Focus me (with Placeholder)"
          @bind-Value="focusedValue"
          placeholder="Enter something here..."
          maxlength="20"
          CssClass="my-custom-input-group"
          class="bg-light border-success"
          OnFocus="@(() => LogEventInput("Input got focus!"))"
          OnBlur="@(() => LogEventInput("Input lost focus!"))" />
<p>Current Value: "@focusedValue"</p>

@* Event Log *@
<div class="bg-light p-4 rounded mb-4">
    <h4 class="mb-3">Event Log</h4>
    <p>This log displays events triggered by the input components, such as focus, blur, and explicit value changes.</p>
    <div class="border p-2" style="height: 150px; overflow-y: scroll; background-color: #f8f9fa;">
        @foreach (var logEntry in eventLogInput)
        {
            <div>@logEntry</div>
        }
    </div>
</div>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? focusedValue = "Focus here";
               
    private List<string> eventLogInput = new List<string>();

    private void LogEventInput(string message)
    {
        eventLogInput.Add($"{DateTime.Now:HH:mm:ss} - {message}");
        if (eventLogInput.Count > 10)
        {
            eventLogInput.RemoveAt(0);
        }
        StateHasChanged();
    }
}


8. Input without Label (Accessibility Warning)

This example intentionally omits the Label parameter. In development mode, this should trigger an accessibility warning on the UI, highlighting the importance of labels for screen readers.

Expected behavior: In development mode, a warning about missing label should appear below the input.
This description has no associated label!

Current Value: "Value without Label"



An input field for a 16-bit integer value (should trigger AOT warning).

Please enter a short integer.

Current value: "3"

Type of the bound value: Int16

Implementation

<h4 class="mb-3">8. Input without Label (Accessibility Warning)</h4>
<p>This example intentionally omits the <code>Label</code> parameter. In development mode, this should trigger an accessibility warning on the UI, highlighting the importance of labels for screen readers.</p>
<div class="alert alert-warning">
    <i class="bi bi-exclamation-triangle me-2"></i>
    Expected behavior: In development mode, a warning about missing label should appear below the input.
</div>
<P11Input @bind-Value="noLabelValue"
          Description="This description has no associated label!" />
<p>Current Value: "@noLabelValue"</p>

<br />
<br />

<p>An input field for a 16-bit integer value (should trigger AOT warning).</p>
<P11Input Label="Short Value"
          @bind-Value="shortValue"
          Description="Please enter a short integer."
          InputType="number"
          ShowDevelopmentErrors="true" /> @* Important: Set ShowDevelopmentErrors to true *@
<p class="mt-2">Current value: "@shortValue"</p>
<p class="text-muted">Type of the bound value: @(shortValue.GetType().Name ?? "null")</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? noLabelValue = "Value without Label";
    private short shortValue { get; set; } = 3;
}


9. InputType 'number' with TValue 'string' (Configuration Warning)

This example intentionally uses InputType="number" with a string TValue. In development mode, this should trigger a configuration warning on the UI, as it's generally not recommended for proper numeric input handling.

Expected behavior: In development mode, a warning about mismatched InputType and TValue should appear below the input.
A warning should appear here, as TValue is String, but InputType is 'number'.

Current Value: "123"

Implementation

<h4 class="mb-3">9. InputType 'number' with TValue 'string' (Configuration Warning)</h4>
<p>This example intentionally uses <code>InputType="number"</code> with a <code>string</code> TValue. In development mode, this should trigger a configuration warning on the UI, as it's generally not recommended for proper numeric input handling.</p>
<div class="alert alert-warning">
    <i class="bi bi-exclamation-triangle me-2"></i>
    Expected behavior: In development mode, a warning about mismatched InputType and TValue should appear below the input.
</div>
<P11Input Label="Text as Number (Warning)"
          @bind-Value="stringAsNumberValue"
          InputType="number"
          Description="A warning should appear here, as TValue is String, but InputType is 'number'." />
<p>Current Value: "@stringAsNumberValue"</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private string? stringAsNumberValue = "123";
}


10. Date Input (using DateTime)

Input field for date selection, using DateTime? as the bound value type.

Select your date of birth. (Format: YYYY-MM-DD)

Current Value: 31.01.2026

Implementation

<h4 class="mb-3">10. Date Input (using DateTime)</h4>
<p>Input field for date selection, using <code>DateTime?</code> as the bound value type.</p>
<P11Input Label="Date of Birth"
          @bind-Value="dateValue"
          InputType="date"
          Culture="@CultureInfo.InvariantCulture"
          Description="Select your date of birth. (Format: YYYY-MM-DD)" />
<p>Current Value: @(dateValue.HasValue? dateValue.Value.ToShortDateString() : "null")</p>
@* You may need the using *@
@* @using System.Globalization *@
@code {
    // C# state for examples
    private DateTime? dateValue = DateTime.Now;
}


11. Input with Additional Html Attributes 'name', 'autocomplete' and 'placeholder'

Submit input field to minimal API ussing html additional attributes to send account and password.

Enter account name.
Enter password.

Implementation

@page "/[YOUR-PAGE]"
@page "/[YOUR-PAGE]/{MyMinimalApiMessage}"

<h4 class="mb-3">11. Input with Additional Attributes 'name', 'autocomplete' and 'placeholder'</h4>
<form id="idLoginForm" action="/api/login" method="post" Model="@myLoginModel">
    <p>Submit input field to minimal API ussing html additional attributes to send account and password.</p>
    <P11Input Label="Account"
              name="account"
              autocomplete="off"
              placeholder="Enter 'admin'' here..."
              @bind-Value="myLoginModel.Account"
              Description="Enter account name."
              InputType="text" />
    <P11Input Label="Password"
              name="password"
              autocomplete="off"
              placeholder="Enter '123'' here..."
              @bind-Value="myLoginModel.Password"
              Description="Enter password."
              InputType="text" />
    <br />
    <P11Button Text="Login" HtmlType="HtmlType.Submit" ButtonVariant="ButtonVariant.Success" OnClick="() => { }" />
</form>

@if (!string.IsNullOrEmpty(MyMinimalApiMessage))
{
    <p>
        <b>Minimal API Message: @MyMinimalApiMessage</b>
    </p>
}
@* Inline-Code  *@
@code {
    public class MyLoginModel
    {
        public string Account { get; set; } = string.Empty;
        public string Password { get; set; } = string.Empty;
    }
    private MyLoginModel myLoginModel = new();
}


@* Program.cs / MAUIProgram.cs  *@
var builder = WebApplication.CreateBuilder(args);
... YOUR CODE HERE ...
var app = builder.Build();
... YOUR CODE HERE ...

// Map Minimal API
app.MapEndPoints(); 

app.Run();


@* Endpoints.cs ([YOUR-PROJECT)/Services/Endpoints.cs  *@
public static void MapEndPoints(this WebApplication app)
{
    // !!!!!!!!!!!!!
    // This is an example to show how to transfer HTML form parameters, NOT an authentication example!
    // !!!!!!!!!!!!!
    app.MapPost("/api/login", async context =>
    {
        await Task.Delay(10);

        var account = context.Request.Form["account"];
        var password = context.Request.Form["password"];

        // !!!!!!!!!!!!!
        // This is an example to show how to transfer HTML form parameters, NOT an authentication example!
        // !!!!!!!!!!!!!
        if(string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
        {
            context.Response.Redirect("/input/Account or password missing!#idLoginForm");
        }
        // !!!!!!!!!!!!!
        // This is an example to show how to transfer HTML form parameters, NOT an authentication example!
        // !!!!!!!!!!!!!
        else if (account != "admin" || password != "123")
        {
            context.Response.Redirect("/input/Invalid account or password!#idLoginForm");
        }
        else
            context.Response.Redirect("/input/Login successful!#idLoginForm");

    }).AllowAnonymous();
}

Component API

Parameter Type Default Description
Label string? null Gets or sets the label text for the input field.
Description string? null Optional helper text displayed below the input field.
Value TValue? null The value of the input. Supports two-way binding using @bind-Value.
InputType string text Specifies the HTML 'type' attribute (text, number, email, password, etc.).
Culture CultureInfo? null (CurrentCulture) Defines the culture used for parsing and formatting numeric values.
ReadOnly bool false If true, the input is rendered with the HTML 'readonly' attribute.
Disabled bool false If true, the input is rendered with the HTML 'disabled' attribute.
Required bool false If true, the field is marked as required using the 'required' attribute.
Autofocus bool false If true, the input will automatically receive focus when rendered.
Placeholder string? null Defines placeholder text displayed when the field is empty.
Pattern string? null Specifies a regex pattern for input validation (HTML5 'pattern' attribute).
Min string? null Specifies the minimum allowed value (used for numeric or date inputs).
Max string? null Specifies the maximum allowed value (used for numeric or date inputs).
Step string? null Specifies valid increments for numeric inputs (e.g. '1', '0.01').
Name string? null Sets the HTML 'name' attribute for form submissions and identification.
Autocomplete string? null Specifies the browser autocomplete behavior (e.g., 'on', 'off', 'email').
InputMode string? null Defines the virtual keyboard type on mobile devices (e.g., 'numeric', 'decimal').
Spellcheck bool? null Enables or disables browser spellchecking ('true', 'false', or null to omit attribute).
CssClass string? null Optional CSS class applied to the outer component wrapper.
ShowDevelopmentErrors bool true If true, internal configuration errors are displayed in development mode.
Events
ValueChanged EventCallback<TValue> - Raised when the component value changes (supports two-way binding).
OnFocus EventCallback<FocusEventArgs> - Raised when the input gains focus.
OnBlur EventCallback<FocusEventArgs> - Raised when the input loses focus.
OnChange EventCallback<ChangeEventArgs> - Raised when the input value is committed (blur, Enter key).
OnKeyDown EventCallback<KeyboardEventArgs> - Raised when a key is pressed while the input has focus.
An unhandled error has occurred. Reload 🗙