Skip to content

Commit 6e03371

Browse files
nimmoloclaude
andcommitted
Allow nil (blank option) at any position in options
Previously nil was only handled as the first option. Now nil renders as a blank option wherever it appears in the collection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0b511ad commit 6e03371

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

lib/superform/rails/components/select.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ def view_template(&block)
3636
select(**attributes, &block)
3737
else
3838
select(**attributes) do
39-
# If first option is nil, render a blank option
40-
include_blank = @options.first.nil?
41-
filtered_options = include_blank ? @options[1..] : @options
42-
43-
blank_option if include_blank
44-
options(*filtered_options)
39+
options(*@options)
4540
end
4641
end
4742
end
@@ -50,7 +45,11 @@ def options(*collection)
5045
# Handle both single values and arrays (for multiple selects)
5146
selected_values = Array(field.value)
5247
map_options(collection).each do |key, value|
53-
option(selected: selected_values.include?(key), value: key) { value }
48+
if key.nil?
49+
blank_option
50+
else
51+
option(selected: selected_values.include?(key), value: key) { value }
52+
end
5453
end
5554
end
5655

0 commit comments

Comments
 (0)