How can I help you?
Disabled Items in Blazor AutoComplete Component
4 Nov 20253 minutes to read
The AutoComplete supports marking individual items as enabled or disabled for specific scenarios. Map the disabled state by using the Disabled field in the data source via AutoCompleteFieldSettings.Disabled. Disabled items cannot be selected.
In the following sample, items are disabled based on the Disabled field value in the bound data.
@using Syncfusion.Blazor.DropDowns
<SfAutoComplete TValue="string" TItem="StatusData" Placeholder="Select Status" DataSource="@LocalData">
<AutoCompleteFieldSettings Value="Text" Disabled="State" ></AutoCompleteFieldSettings>
</SfAutoComplete>
@code {
public IEnumerable<StatusData> LocalData { get; set; } = new StatusData().StatusDataList();
public class StatusData
{
public string Text { get; set; }
public bool State { get; set; }
public List<StatusData> StatusDataList()
{
List<StatusData> staus = new List<StatusData>();
staus.Add(new StatusData { Text = "Open", State = false });
staus.Add(new StatusData { Text = "Waiting for Customer", State = false });
staus.Add(new StatusData { Text = "On Hold", State = true });
staus.Add(new StatusData { Text = "Follow-up", State = false });
staus.Add(new StatusData { Text = "Closed", State = true });
staus.Add(new StatusData { Text = "Solved", State = false });
staus.Add(new StatusData { Text = "Feature Request", State = false });
return staus;
}
}
}Disable Item Method
The disableItem method can be used to change the disabled state of a specific item at runtime. One item can be updated per call. To update multiple items, call this method iteratively for each target item. When an item is disabled using this method, the corresponding Disabled field value in the DataSource is updated. If the currently selected item becomes disabled, the selection is cleared.
| Parameter | Type | Description |
|---|---|---|
| itemValue |
string | number | boolean | object
|
The value of the item to enable or disable (should match the value field type of the bound data). |
| itemIndex | number |
The zero-based index of the item to enable or disable. |
Enabled
To disable the entire component, set the Enabled property to false.
