@page "/"
@using Microsoft.AspNetCore.Components
@using Microsoft.JSInterop
@using System.ComponentModel.DataAnnotations
@inject IComponentContext ComponentContext
@inject IJSRuntime JSRuntime
<h1>Hello, world!</h1>
Welcome to your new app.
<EditForm Model="@model" OnValidSubmit="@(()=>submit(model))">
<DataAnnotationsValidator />
<input id="datet" data-inputmask-alias="datetime" @bind="@model.date" data-inputmask-inputformat="dd/mm/yyyy"
data-inputmask-clearincomplete="true" data-inputmask-placeholder="*" />
<ValidationMessage For="@(()=>@model.date)" />
<input class="btn btn-danger" type="submit" />
</EditForm>
@code
{
public Model model = new Model();
public class Model
{
public DateTime? date { get; set; }
}
protected override async Task OnAfterRenderAsync()
{
if (!ComponentContext.IsConnected)
{
return;
}
await JSRuntime.InvokeAsync<string>("datetimeinput.initjs");
StateHasChanged();
}
public void submit(Model model)
{
Console.WriteLine("model " + model.date);
}
}