Skip to main content

LgYearBox

LgYearBox<TValue> allows you to enter or select a year via a text field combined with a year selector. Unlike the rest of the date family (LgDateBox), the bound value is an integer (int or int?): the year itself.

<LgYearBox Label="#FiscalYear" @bind-Value="_model.FiscalYear" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgInputRenderBase<TValue> → LgInputBase<TValue> → LgAriaComponentBase → LgComponentBase
  • NuGet package: Lagoon.UI

The field suffix is reserved: the component automatically places the calendar icon there (Suffix / SuffixType are overwritten on initialization).

Usage​

Demo​

Try this component in the Lagoon showcase.

Simple input​

BudgetPage.razor
<LgYearBox Label="#FiscalYear" @bind-Value="_model.FiscalYear" />
BudgetPage.razor.cs
public partial class BudgetPage : LgPage
{
// Model being edited: the year is nullable to allow an empty field.
private readonly BudgetVm _model = new();

private sealed class BudgetVm
{
public int? FiscalYear { get; set; }
}
}

Selection bounds​

Min and Max (integers) disable years outside the bounds in the selector.

ArchivePage.razor
<LgYearBox Label="#ArchiveYear"
Min="2000"
Max="2026"
@bind-Value="_model.ArchiveYear" />
ArchivePage.razor.cs
public partial class ArchivePage : LgPage
{
private readonly ArchiveVm _model = new();

private sealed class ArchiveVm
{
public int? ArchiveYear { get; set; }
}
}

Reacting to value changes​

OnChangingAsync is called before the assignment and allows you to cancel the change (args.Cancel); OnChange (inherited) is called after.

CampaignPage.razor
<LgYearBox Label="#CampaignYear"
OnChangingAsync="OnYearChangingAsync"
@bind-Value="_model.CampaignYear" />
CampaignPage.razor.cs
public partial class CampaignPage : LgPage
{
private readonly CampaignVm _model = new();

// Called before the change: refuses years with no known campaign.
private Task OnYearChangingAsync(ChangingEventArgs<int?> args)
{
if (args.NewValue < 2010)
{
args.Cancel = true;
ShowWarning("#NoCampaignBefore2010");
}
return Task.CompletedTask;
}

private sealed class CampaignVm
{
public int? CampaignYear { get; set; }
}
}

Properties​

All [Parameter] properties of the component, including inherited ones.

NameTypeDefaultDeclared inDescription
Maxint?nullLgYearBoxLatest selectable year; later years are disabled.
Minint?nullLgYearBoxEarliest selectable year; earlier years are disabled.
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>nullLgYearBoxCallback called before the value changes; the change can be canceled there.
OnFocusEventCallback<FocusEventArgs>—LgYearBoxCallback called when focus is taken.
PlaceholderstringnullLgYearBoxIndicator text displayed when the field is empty.
PrefixstringnullLgInputRenderBasePrefix displayed in the field.
PrefixTypeInputLabelTypeTextLgInputRenderBaseNature of the prefix.
Suffixstring(calendar icon)LgInputRenderBaseSuffix displayed in the field. Reserved: the component places the calendar icon there.
SuffixTypeInputLabelTypeIconNameLgInputRenderBaseNature of the suffix. Reserved by the component.
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgInputBaseAdditional HTML attributes applied to the rendered element.
AutoFocusboolfalseLgInputBaseGives focus to the field on first render.
ConfirmationMessagestringnullLgInputBaseConfirmation message displayed before applying a value change.
ContainerIInputContainer<TValue>nullLgInputBaseInternal use: attaches a GridView cell to the field.
CssClassstringnullLgInputBaseAdditional CSS classes.
DisabledboolfalseLgInputBaseDisables the field.
DisplayNamestringnullLgInputBaseName of the field used in input error messages.
HideValidationMessageboolfalseLgInputBaseHides the validation message below the field.
LabelstringnullLgInputBaseField label.
LabelContentRenderFragmentnullLgInputBaseCustom content of the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback called after the value changes.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called when the field is reset by the clear button.
PolicyEditstringnullLgInputBasePolicy required to edit the field.
PolicyVisiblestringnullLgInputBasePolicy required to display the field.
ReadOnlyboolfalseLgInputBaseDisplays the field as read-only.
Requiredbool?nullLgInputBaseRequired field. If null, inferred from the [Required] attribute of the bound property.
ResetButtonbool?nullLgInputBaseDisplays the clear button. If null, the application's behavior configuration applies.
ResetTextstringnullLgInputBaseClear button text.
ResetTextAriaLabelstringnullLgInputBaseAccessible label (aria-label) of the clear button.
TooltipstringnullLgInputBaseHelp tooltip.
TooltipIsHtmlboolfalseLgInputBaseIndicates whether the Tooltip content is in HTML format (otherwise plain text).
ValueTValue—LgInputBaseBound value (@bind-Value), of type int or int?.
ValueChangedEventCallback<TValue>—LgInputBaseCallback for updating the bound value.
ValueExpressionExpression<Func<TValue>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

LgYearBox also consumes parameters automatically provided by ancestor components (you don't need to define them): ParentAuthorizeView (LgAuthorizeView) and the edit context of a parent LgEditForm.

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>Before the value changes; args.Cancel = true cancels the change.
OnChangeEventCallback<ChangeEventArgs>After the value changes.
OnFocusEventCallback<FocusEventArgs>When the field takes focus.
OnResetEventCallback<ChangeEventArgs>When reset by the clear button.

Best practices / accessibility​

  • The bound value must be int or int?: any other type causes a runtime error.
  • Do not set Suffix / SuffixType: they are overwritten by the calendar icon on component initialization.
Complete reference

All parameters (including inherited): API Reference — LgYearBox.