Custom Numeric Component

Hi,

1- How to create a custom numeric component using SfNumericTextBox?

2- I used SfAutoComplete. I introduced a list of numbers as DataSource. How do we allow the user to type only a number?


thank you


5 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team June 24, 2022 12:13 PM UTC

Query 1: How to create a custom numeric component using SfNumericTextBox?

Find the custom numeric text box component rendering here:

[parent component]

@typeparam TVal;

 

 

<SfNumericTextBox Value="@Value" ValueChanged="ValueChanged" ValueExpression="@ValueExpression" TValue="TVal">

</SfNumericTextBox>

 

@code

{

    private TVal _value { get; set; }

    [Parameter]

    public string ID { get; set; }

    [Parameter]

    public Expression<Func<TVal>> ValueExpression { get; set; }

    [Parameter]

    public TVal Value

    {

        get => _value;

        set

        {

            if (!EqualityComparer<TVal>.Default.Equals(value, _value))

            {

                _value = value;

                ValueChanged.InvokeAsync(value);

            }

        }

    }

    [Parameter]

    public EventCallback<TVal> ValueChanged { get; set; }

}

 

 

[child component]

<CustomTextbox TVal="int?" @bind-Value="@NumericValue"></CustomTextbox>

 

@code {

    public int? NumericValue { get; set; }

}


Query 2: I used SfAutoComplete. I introduced a list of numbers as DataSource. How do we allow the user to type only a number?

You can achieve your requirement by setting the type attribute as a number by using the HtmlAttributes property.

Find the code example here:

@using Syncfusion.Blazor.DropDowns

@using System.Collections.Generic

 

<SfAutoComplete TValue="string" TItem="Country" Placeholder="e.g. Australia" DataSource="@Countries" HtmlAttributes="@TypeChange">

    <AutoCompleteFieldSettings Value="Name"></AutoCompleteFieldSettings>

</SfAutoComplete>

 

@code {

    Dictionary<string, object> TypeChange = new Dictionary<string, object>()

     {

        { "type", "number"} };

 

 

    public class Country

    {

        public int Name { get; set; }

 

        public int Code { get; set; }

    }

 

    List<Country> Countries = new List<Country>

    {

        new Country() { Name = 1, Code = 1 },

        new Country() { Name = 2, Code = 2 },

        new Country() { Name = 3, Code = 3 },

        new Country() { Name = 4, Code = 4 }

    };

}

Find the sample in the attachment:


Attachment: CustomControls_670c278e.zip

Marked as answer

SA Sarah replied to Sureshkumar P June 25, 2022 08:59 AM UTC

Hi , 


Thank you. How can the following icons be hidden?


SfAutoComplete  :


SfNumericTextBox :





SP Sureshkumar P Syncfusion Team June 27, 2022 07:04 AM UTC

HI Sarah,

Query: How can the following icons be hidden?

In our numeric textbox component, we can hide the spin button by setting false for the ShowSpinButton property. And the autocomplete default number type input icons are disabled by using the below CSS styles.

Find the code example here:

<SfNumericTextBox Value="@Value" ValueChanged="ValueChanged" ValueExpression="@ValueExpression" TValue="TVal" ShowSpinButton="@showSpinButton">

</SfNumericTextBox>

 

<style>

    /* Chrome, Safari, Edge, Opera */

    input::-webkit-outer-spin-button,

    input::-webkit-inner-spin-button {

        -webkit-appearance: none;

        margin: 0;

    }

 

    /* Firefox */

    input[type=number] {

        -moz-appearance: textfield;

    }

</style>

Find the modified sample in the attachment:

Regards,

Sureshkumar P


Attachment: CustomControls_9aa32c1f.zip


SA Sarah June 28, 2022 06:44 AM UTC

Hi  Sureshkumar P,


The bug was fixed.


thank you



SP Sureshkumar P Syncfusion Team June 29, 2022 05:19 AM UTC

Sarah,


Thanks for your update.


Regards,

Sureshkumar P


Loader.
Up arrow icon