Skip to content

Commit

Permalink
fix: possible nil panics
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Dec 7, 2023
1 parent aeb5620 commit 612f646
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions field_multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type MultiSelect[T any] struct {
// NewMultiSelect returns a new multi-select field.
func NewMultiSelect[T any]() *MultiSelect[T] {
return &MultiSelect[T]{
options: []Option[T]{},
value: new([]T),
validate: func([]T) error { return nil },
}
Expand Down Expand Up @@ -72,6 +73,9 @@ func (m *MultiSelect[T]) Description(description string) *MultiSelect[T] {

// Options sets the options of the multi-select field.
func (m *MultiSelect[T]) Options(options ...Option[T]) *MultiSelect[T] {
if len(options) <= 0 {
return m
}
m.options = options
return m
}
Expand Down
4 changes: 4 additions & 0 deletions field_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewSelect[T any]() *Select[T] {
filter.Prompt = "/"

return &Select[T]{
options: []Option[T]{},
value: new(T),
validate: func(T) error { return nil },
filtering: false,
Expand Down Expand Up @@ -79,6 +80,9 @@ func (s *Select[T]) Description(description string) *Select[T] {

// Options sets the options of the select field.
func (s *Select[T]) Options(options ...Option[T]) *Select[T] {
if len(options) <= 0 {
return s
}
s.options = options
s.filteredOptions = options

Expand Down

0 comments on commit 612f646

Please sign in to comment.