Table of Contents

Class MudForm

Namespace
MudBlazor
Assembly
MudBlazor.dll
public class MudForm : MudComponentBase, IComponent, IHandleEvent, IHandleAfterRender, IMudStateHasChanged, IDisposable, IForm
Inheritance
MudForm
Implements
Inherited Members
Extension Methods

Constructors

MudForm()

public MudForm()

Fields

_errors

protected HashSet<string> _errors

Field Value

HashSet<string>

_formControls

protected HashSet<IFormComponent> _formControls

Field Value

HashSet<IFormComponent>

Properties

ChildContent

Child content of component.

[Parameter]
[Category("Validated data")]
public RenderFragment ChildContent { get; set; }

Property Value

RenderFragment

Classname

protected string Classname { get; }

Property Value

string

Disabled

[Parameter]
[Category("Behavior")]
public bool Disabled { get; set; }

Property Value

bool

Errors

Validation error messages.

[Parameter]
[Category("Validation result")]
public string[] Errors { get; set; }

Property Value

string[]

ErrorsChanged

[Parameter]
public EventCallback<string[]> ErrorsChanged { get; set; }

Property Value

EventCallback<string[]>

FieldChanged

Raised when a contained IFormComponent changes its value

[Parameter]
public EventCallback<FormFieldChangedEventArgs> FieldChanged { get; set; }

Property Value

EventCallback<FormFieldChangedEventArgs>

IsTouched

True if any field of the field was touched. This parameter is readonly.

[Parameter]
[Category("Behavior")]
public bool IsTouched { get; set; }

Property Value

bool

IsTouchedChanged

Raised when IsTouched changes.

[Parameter]
public EventCallback<bool> IsTouchedChanged { get; set; }

Property Value

EventCallback<bool>

IsValid

Validation status. True if the form is valid and without errors. This parameter is two-way bindable.

[Parameter]
[Category("Validation result")]
public bool IsValid { get; set; }

Property Value

bool

IsValidChanged

Raised when IsValid changes.

[Parameter]
public EventCallback<bool> IsValidChanged { get; set; }

Property Value

EventCallback<bool>

Model

Specifies the top-level model object for the form. Used with Fluent Validation

[Parameter]
[Category("Validated data")]
public object? Model { get; set; }

Property Value

object

OverrideFieldValidation

If a field already has a validation, override it with Validation.

[Parameter]
[Category("Validation")]
public bool? OverrideFieldValidation { get; set; }

Property Value

bool?

ReadOnly

[Parameter]
[Category("Behavior")]
public bool ReadOnly { get; set; }

Property Value

bool

Spacing

The gap between items, measured in increments of 4px.
Maximum is 20.
Default is no spacing.

[Parameter]
[Category("Behavior")]
public int Spacing { get; set; }

Property Value

int

SuppressImplicitSubmission

When true, will not cause a page refresh on Enter if any input has focus.

[Parameter]
[Category("Behavior")]
public bool SuppressImplicitSubmission { get; set; }

Property Value

bool

Remarks

https://www.w3.org/TR/2018/SPSD-html5-20180327/forms.html#implicit-submission Usually this is not wanted, as it can cause a page refresh in the middle of editing a form. When the form is in a dialog this will cause the dialog to close. So by default we suppress it.

SuppressRenderingOnValidation

When true, the form will not re-render its child contents on validation updates (i.e. when IsValid changes). This is an optimization which can be necessary especially for larger forms on older devices.

[Parameter]
[Category("Behavior")]
public bool SuppressRenderingOnValidation { get; set; }

Property Value

bool

Validation

A default validation func or a validation attribute to use for form controls that don't have one. Supported types are:

Func<T, bool> ... will output the standard error message "Invalid" if false

Func<T, string> ... outputs the result as error message, no error if null

Func<T, IEnumerable< string >> ... outputs all the returned error messages, no error if empty

Func<object, string, IEnumerable< string >> input Form.Model, Full Path of Member ... outputs all the returned error messages, no error if empty

Func<T, Task< bool >> ... will output the standard error message "Invalid" if false

Func<T, Task< string >> ... outputs the result as error message, no error if null

Func<T, Task<IEnumerable< string >>> ... outputs all the returned error messages, no error if empty

Func<object, string, Task<IEnumerable< string >>> input Form.Model, Full Path of Member ... outputs all the returned error messages, no error if empty

System.ComponentModel.DataAnnotations.ValidationAttribute instances

[Parameter]
[Category("Validation")]
public object Validation { get; set; }

Property Value

object

ValidationDelay

Validation debounce delay in milliseconds. This can help improve rendering performance of forms with real-time validation of inputs i.e. when textfields have Immediate="true".

[Parameter]
[Category("Behavior")]
public int ValidationDelay { get; set; }

Property Value

int

Methods

BuildRenderTree(RenderTreeBuilder)

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

Dispose()

public void Dispose()

GetDisabledState()

protected bool GetDisabledState()

Returns

bool

GetReadOnlyState()

protected bool GetReadOnlyState()

Returns

bool

OnAfterRenderAsync(bool)

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

OnEvaluateForm()

protected Task OnEvaluateForm()

Returns

Task

OnInitialized()

protected override void OnInitialized()

ResetAsync()

Reset all form controls and reset their validation state.

public Task ResetAsync()

Returns

Task

ResetTouched()

Reset the isTouched property

public void ResetTouched()

ResetValidation()

Reset the validation state but keep the values.

public void ResetValidation()

ShouldRender()

protected override bool ShouldRender()

Returns

bool

Validate()

Force a validation of all form controls, even if they haven't been touched by the user yet.

public Task Validate()

Returns

Task