Example of Disabled Items in ASP.NET MVC AutoComplete Control
This example showcases the disabled items of AutoComplete. When you type on the AutoComplete the popup will open, and you will notice that the disabled items are greyed out and cannot be selected.
Vegetable
@Html.UiAutoComplete("status", new UiAutoCompleteOptions
{
Placeholder = "Select Status",
DataSource = (IEnumerable<DropdownsDemoController.DisableStatusData>)ViewData["statusdata"],
Fields = new UiDropDownFields { Text = "Status", Disabled = "State" }
})
@Html.UiAutoComplete("vegetable", new UiAutoCompleteOptions
{
Placeholder = "Select Vegetable",
DataSource = (IEnumerable<DropdownsDemoController.VegetableData>)ViewData["vegetabledata"],
Fields = new UiDropDownFields { GroupBy = "Category", Text = "Vegetable", Disabled = "Status" }
})
<style>
.control-section .content { margin: 0 auto; width: 250px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div id="statusList" style="padding-top:15px">
<div class="content">
<h3> Status </h3>
@Html.UiAutoComplete("status", new UiAutoCompleteOptions
{
Placeholder = "Select Status",
DataSource = (IEnumerable<DropdownsDemoController.DisableStatusData>)ViewData["statusdata"],
Fields = new UiDropDownFields { Text = "Status", Disabled = "State" }
})
</div>
</div>
<div id="vegetableList" style="padding-top:15px">
<div class="content">
<h3> Vegetable </h3>
@Html.UiAutoComplete("vegetable", new UiAutoCompleteOptions
{
Placeholder = "Select Vegetable",
DataSource = (IEnumerable<DropdownsDemoController.VegetableData>)ViewData["vegetabledata"],
Fields = new UiDropDownFields { GroupBy = "Category", Text = "Vegetable", Disabled = "Status" }
})
</div>
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class AutoCompleteController : Controller
{
// The page is Views/AutoComplete/DisabledItems.cshtml; it draws what ViewData holds.
public ActionResult DisabledItems()
{
ViewData["statusdata"] = new DisableStatusData().StatusDataList();
ViewData["vegetabledata"] = new VegetableData().VegetableDataList();
return View();
}
public class DisableStatusData
{
public string Status { get; set; }
public bool State { get; set; }
public List<DisableStatusData> StatusDataList()
{
List<DisableStatusData> status = new List<DisableStatusData>();
status.Add(new DisableStatusData() { Status = "Open", State = false });
status.Add(new DisableStatusData() { Status = "Waiting for Customer", State = false });
status.Add(new DisableStatusData() { Status = "On Hold", State = true });
status.Add(new DisableStatusData() { Status = "Follow-up", State = false });
status.Add(new DisableStatusData() { Status = "Closed", State = true });
status.Add(new DisableStatusData() { Status = "Solved", State = false });
status.Add(new DisableStatusData() { Status = "Feature Request", State = false });
return status;
}
}
public class VegetableData
{
public string Vegetable { get; set; }
public string Category { get; set; }
public bool Status { get; set; }
public List<VegetableData> VegetableDataList()
{
List<VegetableData> veg = new List<VegetableData>();
veg.Add(new VegetableData { Vegetable = "Cabbage", Category = "Leafy and Salad", Status = true });
veg.Add(new VegetableData { Vegetable = "Pumpkins", Category = "Leafy and Salad", Status = false });
veg.Add(new VegetableData { Vegetable = "Spinach", Category = "Leafy and Salad", Status = true });
veg.Add(new VegetableData { Vegetable = "Wheat grass", Category = "Leafy and Salad", Status = false });
veg.Add(new VegetableData { Vegetable = "Yarrow", Category = "Leafy and Salad", Status = false });
veg.Add(new VegetableData { Vegetable = "Chickpea", Category = "Beans", Status = true });
veg.Add(new VegetableData { Vegetable = "Green bean", Category = "Beans", Status = false });
veg.Add(new VegetableData { Vegetable = "Horse gram", Category = "Beans", Status = true });
veg.Add(new VegetableData { Vegetable = "Garlic", Category = "Bulb and Stem", Status = false });
veg.Add(new VegetableData { Vegetable = "Nopal", Category = "Bulb and Stem", Status = true });
veg.Add(new VegetableData { Vegetable = "Onion", Category = "Bulb and Stem", Status = false });
return veg;
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The AutoComplete provides options for individual items to be in either an enabled or disabled state for specific scenarios. Once an item is disabled, it cannot be selected as a value for the component. To configure the disabled item columns, use the fields.disabled property.