ComboBox

in namespace DotVVM.Controls.Tailwind.Controls

Usage & Scenarios

The Tailwind ComboBox uses the same API as the built-in ComboBox and only adds Tailwind styling. Use ComboBoxFormField for labeled form layouts.

Sample 1: Styled ComboBox

The Tailwind ComboBox keeps the built-in ComboBox API, so all binding patterns from the built-in ComboBox documentation apply here as well. This sample shows the Tailwind styling with DataSource, item bindings, Enabled, and SelectionChanged.

<div class="space-y-3 max-w-md">
    <t:CheckBox Text="Enable ComboBox" Checked="{value: IsEnabled}" />

    <t:ComboBox DataSource="{value: Countries}"
                SelectedValue="{value: SelectedCountry}"
                ItemTextBinding="{value: Name}"
                ItemValueBinding="{value: Code}"
                EmptyItemText="-- choose a country --"
                Enabled="{value: IsEnabled}"
                SelectionChanged="{command: IncrementChanges()}" />
</div>

<p>Selected country: <strong>{{value: SelectedCountry ?? "(none)"}}</strong></p>
<p><code>SelectionChanged</code> command count: <strong>{{value: ChangeCount}}</strong></p>
using DotVVM.Framework.ViewModel;
using System.Collections.Generic;

namespace DotvvmWeb.Views.Docs.Controls.tailwind.ComboBox.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public List<Country> Countries { get; set; } =
        [
            new() { Code = "cz", Name = "Czech Republic" },
            new() { Code = "de", Name = "Germany" },
            new() { Code = "us", Name = "United States" }
        ];

        public string? SelectedCountry { get; set; } = "cz";

        public bool IsEnabled { get; set; } = true;

        public int ChangeCount { get; set; }

        public void IncrementChanges()
        {
            ChangeCount++;
        }
    }

    public class Country
    {
        public string Code { get; set; }

        public string Name { get; set; }
    }
}

Properties

Name Type Description Notes Default Value
property icon DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
null
property icon EmptyItemText String Text displayed when no value is selected.
attribute
inner element
static value
bindable
default
property icon Enabled Boolean Gets or sets a value indicating whether the control is enabled and can be modified.
attribute
inner element
static value
bindable
default
True
property icon ItemTextBinding IValueBinding<String> The expression of DataSource item that will be displayed in the control.
attribute
inner element
static value
bindable
default
null
property icon ItemTitleBinding IValueBinding The expression of DataSource item that will be placed into html title attribute.
attribute
inner element
static value
bindable
default
null
property icon ItemValueBinding IValueBinding The expression of DataSource item that will be passed to the SelectedValue property when the item is selected.
attribute
inner element
static value
bindable
default
null
property icon SelectedValue Object Gets or sets the value of the selected item.
attribute
inner element
static value
bindable
default
null

Events

Name Type Description
event icon SelectionChanged Command Gets or sets the command that will be triggered when the selection is changed.

HTML produced by the control