We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Clear Text

Thread ID:

Created:

Updated:

Platform:

Replies:

146994 Aug 27,2019 11:40 PM UTC Aug 29,2019 09:22 AM UTC Blazor 3
loading
Tags: Dropdown List
Raul
Asked On August 27, 2019 11:40 PM UTC

Hi, how do I clear the control form code?

Gopi Govindasamy [Syncfusion]
Replied On August 28, 2019 10:08 AM UTC

Hi Raul,  

As per our understanding, you expect to clear value from code. If you need to clear the value dynamically from code, use Value property and set it as null.  

Please find the code snippet for your reference.  

@using Syncfusion.EJ2.Blazor.DropDowns 
 
<div> 
    <button @onclick="@OnClick">Clear Text</button> 
</div> 
<EjsDropDownList @bind-Value="@selectCountry" ShowClearButton="true" DataSource="@Country"> 
    <DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings> 
</EjsDropDownList> 
 
@code{ 
 
    private string selectCountry;  
 
    public void OnClick(UIMouseEventArgs args) 
    { 
        this.selectCountry = null; 
    } 
 
   public class Countries 
    { 
        public string Name { get; set; } 
 
        public string Code { get; set; } 
    } 
 
    List<Countries> Country = new List<Countries> 
{ 
        new Countries() { Name = "Australia", Code = "AU" }, 
        new Countries() { Name = "Bermuda", Code = "BM" }, 
        new Countries() { Name = "Canada", Code = "CA" }, 
        new Countries() { Name = "Cameroon", Code = "CM" }, 
    }; 
} 


If you want clear control value from UI, we have provided “ShowClearButton” property to show the clear button that reset value, text, and index properties. 

Regards, 
Gopi G. 


Raul
Replied On August 28, 2019 07:32 PM UTC

I had already tried it that way, my value is an int, and I have a property:
    private int? vehicleBrandId;

    public int? VehicleBrandId
    {
        get { return vehicleBrandId; }
        set
        {
            vehicleBrandId = value;
            this.StateHasChanged();
        }
    }

and the control:
            <EjsDropDownList ID="brands" PlaceHolder="Select the brand" @bind-Value="VehicleBrandId" DataSource="@VehicleBrands">
                <DropDownListEvents TValue="TanCoLogisticsSDK.VehicleBrand" OnValueSelect="onSelectBrand"></DropDownListEvents>
                <DropDownListFieldSettings Text="BrandName" Value="VehicleBrandID"></DropDownListFieldSettings>
            </EjsDropDownList>

then to test on a click of a button I set 
this.VehicleBrandId = null;
but the droplist still shows the selected brand, instead of clear it self like when the control is first rendered.

Gopi Govindasamy [Syncfusion]
Replied On August 29, 2019 09:22 AM UTC

Hi Raul,  

Thanks for your update. 

We have validated your reported issue with shared code snippet. You have used incorrect datatype to TValue into DropDownListEvent. You can set the datatypes of Value property into TValue (TValue="int?"). We have prepared sample based on shared code snippet. Please find the sample and code snippet for your reference.  

<div> 
    <button @onclick="@OnClick">Clear Text</button> 
</div> 
 
<EjsDropDownList ID="brands" @ref:suppressField @ref="DropDownObj" Placeholder="Select the brand" @bind-Value="@VehicleBrandId" DataSource="@VehicleBrands"> 
    <DropDownListEvents TValue="int?" OnValueSelect="onSelectBrand"></DropDownListEvents> 
    <DropDownListFieldSettings Text="BrandName" Value="VehicleBrandID"></DropDownListFieldSettings> 
</EjsDropDownList> 
 
 
@code{  
 
    EjsDropDownList<int?> DropDownObj; 
      
    public int? VehicleBrandId 
    { 
        get { return vehicleBrandId; } 
        set 
        { 
            vehicleBrandId = value; 
        } 
    } 
    protected int? vehicleBrandId { get; set; } = 2; 
 
    public class Vehicles 
    { 
        public string BrandName { get; set; } 
 
        public int VehicleBrandID { get; set; } 
    } 
 
 
    public void OnClick(UIMouseEventArgs args) 
    { 
        this.VehicleBrandId = null; 
        this.DropDownObj.Text = null; 
        this.DropDownObj.Index = null; 
    } 


Regards,
Gopi G. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon