Skip to content

Instantly share code, notes, and snippets.

@elorest
Created November 7, 2018 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elorest/414e28812520a585fbf909649ed489a8 to your computer and use it in GitHub Desktop.
Save elorest/414e28812520a585fbf909649ed489a8 to your computer and use it in GitHub Desktop.
def select_field(name : String | Symbol, collection : Array(Array), **options : Object)
options_hash = Kit.safe_hash(options, {:name => name})
selected = [options_hash.delete(:selected)].flatten.map(&.to_s)
content(element_name: :select, options: options_hash) do
String.build do |str|
collection.map do |item|
str << %(<option value="#{item[0]}"#{selected.includes?(item[0].to_s) ? %( selected="selected") : nil}>#{item[1]}</option>)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment