diff --git a/Radzen.Blazor/RadzenDropDown.razor b/Radzen.Blazor/RadzenDropDown.razor
index 3f2bdff49..5212d1aa7 100644
--- a/Radzen.Blazor/RadzenDropDown.razor
+++ b/Radzen.Blazor/RadzenDropDown.razor
@@ -19,10 +19,10 @@
aria-label="@(!Multiple && internalValue != null ? internalValue : EmptyAriaLabel)" @attributes="InputAttributes"/>
- @if (ValueTemplate != null && selectedItem != null)
+ @if (ValueTemplate != null && (selectedItem != null || (ShowValueTemplateOnEmpty && !Multiple)))
{
- @ValueTemplate(selectedItem)
+ @ValueTemplate(selectedItem!)
}
else if (Template != null && selectedItem != null)
diff --git a/Radzen.Blazor/RadzenDropDown.razor.cs b/Radzen.Blazor/RadzenDropDown.razor.cs
index 789d7e5bc..74408f8d6 100644
--- a/Radzen.Blazor/RadzenDropDown.razor.cs
+++ b/Radzen.Blazor/RadzenDropDown.razor.cs
@@ -65,6 +65,15 @@ namespace Radzen.Blazor
[Parameter]
public RenderFragment? ValueTemplate { get; set; }
+ ///
+ /// Gets or sets whether is rendered even when there is no selected item.
+ /// When true, the template is invoked with a null context so it can render an editor
+ /// (e.g. a text box) for an empty value. Templates must handle a null context.
+ ///
+ /// true to render on empty value; otherwise false. Default is false.
+ [Parameter]
+ public bool ShowValueTemplateOnEmpty { get; set; }
+
///
/// Gets or sets the template displayed when the dropdown data source is empty or no items match the filter.
/// Use this to show a custom "No items found" or "Empty list" message.
diff --git a/Radzen.Blazor/RadzenDropDownDataGrid.razor b/Radzen.Blazor/RadzenDropDownDataGrid.razor
index 0ad5593b6..3864d7584 100644
--- a/Radzen.Blazor/RadzenDropDownDataGrid.razor
+++ b/Radzen.Blazor/RadzenDropDownDataGrid.razor
@@ -18,10 +18,10 @@
- @if (ValueTemplate != null && selectedItem != null)
+ @if (ValueTemplate != null && (selectedItem != null || (ShowValueTemplateOnEmpty && !Multiple)))
{
- @ValueTemplate(selectedItem)
+ @ValueTemplate(selectedItem!)
}
else if (Template != null && selectedItem != null)
diff --git a/Radzen.Blazor/RadzenDropDownDataGrid.razor.cs b/Radzen.Blazor/RadzenDropDownDataGrid.razor.cs
index 2649ae002..0b4e7c67a 100644
--- a/Radzen.Blazor/RadzenDropDownDataGrid.razor.cs
+++ b/Radzen.Blazor/RadzenDropDownDataGrid.razor.cs
@@ -257,6 +257,15 @@ namespace Radzen.Blazor
[Parameter]
public RenderFragment? ValueTemplate { get; set; }
+ ///
+ /// Gets or sets whether is rendered even when there is no selected item.
+ /// When true, the template is invoked with a null context so it can render an editor
+ /// (e.g. a text box) for an empty value. Templates must handle a null context.
+ ///
+ /// true to render on empty value; otherwise false. Default is false.
+ [Parameter]
+ public bool ShowValueTemplateOnEmpty { get; set; }
+
///
/// Gets or sets a value indicating DataGrid density.
///
diff --git a/RadzenBlazorDemos/Pages/DropDownEdit.razor b/RadzenBlazorDemos/Pages/DropDownEdit.razor
index cbd43bcc4..09cc3f661 100644
--- a/RadzenBlazorDemos/Pages/DropDownEdit.razor
+++ b/RadzenBlazorDemos/Pages/DropDownEdit.razor
@@ -1,8 +1,8 @@
@inherits DbContextPage
-
-
+
+
@@ -10,7 +10,7 @@
@code {
- string value = "Around the Horn";
+ string value = "";
IEnumerable companyNames;
protected override async Task OnInitializedAsync()
diff --git a/RadzenBlazorDemos/Pages/DropDownPage.razor b/RadzenBlazorDemos/Pages/DropDownPage.razor
index ff879bef2..4642a9cd8 100644
--- a/RadzenBlazorDemos/Pages/DropDownPage.razor
+++ b/RadzenBlazorDemos/Pages/DropDownPage.razor
@@ -71,7 +71,7 @@
Editable DropDown
- Use the AllowFiltering property to enable editable mode, allowing users to type and filter dropdown items.
+ Use the ValueTemplate with an embedded input bound to the same value to let users edit the selected item in place. Set ShowValueTemplateOnEmpty to true to render the template (and its editor) even when no item is selected, so the user can type an initial value without first picking from the list. The pattern requires the DropDown Value to be the displayed text itself (e.g. a primitive type) and is not designed for use with TextProperty/ValueProperty.