Select
Нативный dropdown из слайса Options.
github.com/fastygo/templ/ui
Select рендерит нативный выпадающий список из слайса Options. Выбранный option отмечается, когда Value совпадает с Option Value.
По умолчанию
import "github.com/fastygo/templ/ui"
import "github.com/fastygo/templ/ui/select"
templ Example() {
@ui.Select(ui.SelectProps{
Name: "country",
Value: "us",
Options: []selectfield.Option{
{Value: "us", Label: "США"},
{Value: "ca", Label: "Канада"},
},
})
}
import "github.com/fastygo/templ/ui"
import "github.com/fastygo/templ/ui/select"
templ Example() {
@ui.Select(ui.SelectProps{
Name: "country",
Value: "us",
Options: []selectfield.Option{
{Value: "us", Label: "США"},
{Value: "ca", Label: "Канада"},
},
})
}
Неактивный
import "github.com/fastygo/templ/ui"
import "github.com/fastygo/templ/ui/select"
templ Example() {
@ui.Select(ui.SelectProps{
Disabled: true,
Name: "locked",
Options: []selectfield.Option{
{Value: "a", Label: "Вариант A"},
},
})
}
import "github.com/fastygo/templ/ui"
import "github.com/fastygo/templ/ui/select"
templ Example() {
@ui.Select(ui.SelectProps{
Disabled: true,
Name: "locked",
Options: []selectfield.Option{
{Value: "a", Label: "Вариант A"},
},
})
}
API
Name · string — Имя поля формы
Value · string — Выбранное значение
Options · []Option — Список вариантов Value и Label
Disabled · bool — Неактивное состояние