// ContentID is the HTML element ID where content for this option is rendered when OptionsContent is rendered
func (i Option) ContentID() string {
return fmt.Sprintf("option-%s-content", i.ID)
}
// SelectArgs are the arguments used to initialize selector.Selector
//
// ID: element ID for the <select> element
//
// Label: The <label> for the <select> element
//
// LabelClass: The CSS class(es) for the <label> element
//
// Multiple: Allow multiple items to be selected
//
// Name: The <select> form element name
//
// Options: The <option>s available to be <select>ed. Use either Options or OptionsContent to provide options to selector.Seletor
//
// OptionsContent: The <option>s available to be <select>ed, and the content to be conditionally rendered when option is selected. Use either Options or OptionsContent, but not both.
//
// Placeholder: Placeholder text shown in the search box
//
// SearchDisabled: Disable the ability to search for items
//
// EditItems: Allow new items to be created through the ui
//
// SelectionChangeEvent: The name of the DOM event to trigger when selections change. This event bubbles. It is triggered on the selector element, which does not handle it. An element up the DOM tree should handle it.
//
// Hyperscript: Attach a hyperscript _ attribute to the <select>.
type SelectArgs struct {
ID string
Label string
LabelClass string
Multiple bool
Name string
Options FieldOptions
OptionsContent map[Option]templ.Component
Placeholder string
Required bool
SearchDisabled bool
EditItems bool
SelectionChangeEvent string
Hyperscript string
}
// MarhsahJSON allows SelectArgs to be serialized to JSON, to be added as a `data-*` field for latest access
func (a SelectArgs) MarshalJSON() (b []byte, err error) {
d := struct {
ID string
Name string
Label string
LabelClass string
Options []Option
OptionsContent map[string]string // mapping of opton ID to the ID of the HTML element where content should render when selected