skclusive / Skclusive.Material.Component

Port of Material-UI in C# for Blazor
https://skclusive.github.io/Skclusive.Blazor.Samples/Dashboard
MIT License
397 stars 55 forks source link

Input field double, decimal #83

Open kevinvenclovas opened 3 years ago

kevinvenclovas commented 3 years ago

Is there a component to bind a double or decimal to an input field?

@skclusive

skclusive commented 3 years ago

no. text field accepts string as value. but we can restrict type to number and parse the value from string as below.

    <TextField
        Id="fillted-number"
        Label="Number"
        Value="@Age?.ToString()"
        OnChange="@HandleAgeChange"
        Type="number"
        Class="demo-text-field"
        Margin="@Margin.Normal"
        Variant="@TextFieldVariant.Filled" />
    private void HandleAgeChange(ChangeEventArgs args)
    {
        if (int.TryParse(args.Value?.ToString(), out int age))
        {
            Age = age;

            StateHasChanged();
        }
    }