Some arguments for UI components are optional, so we don't have to provide all of them when using them. I had added a `defined?(name)` check to use default values when an argument is not provided. Jeremy pointed out that it was working by accident. In the code `name = defined?(name)`, `defined?(name)` always returns `local-variable` because it’s on the right-hand side of the assignment, while the local variable is on the left-hand side. When we remove the `defined?` calls, the remaining code is equivalent to `||=`.
44 lines
1.5 KiB
Plaintext
44 lines
1.5 KiB
Plaintext
<% name ||= nil
|
|
label ||= nil
|
|
options ||= {}
|
|
selected = flash.dig("old", name) || selected
|
|
error ||= rodauth.field_error(name) || flash.dig("errors", name)
|
|
description ||= nil
|
|
attributes ||= {} %>
|
|
|
|
<div class="space-y-2 text-gray-900">
|
|
<% if label %>
|
|
<label for="<%= name %>" class="block text-sm font-medium leading-6"><%== label %></label>
|
|
<% end %>
|
|
<fieldset>
|
|
<div class="space-y-5">
|
|
<% options.each do |opt_val, opt_text, opt_classes, opt_attrs| %>
|
|
<div class="relative flex items-start">
|
|
<div class="flex h-6 items-center">
|
|
<input
|
|
id="<%= name %>-<%= opt_val %>"
|
|
name="<%= name %>"
|
|
type="checkbox"
|
|
value="<%= opt_val %>"
|
|
class="h-4 w-4 rounded border-gray-300 text-orange-600 focus:ring-orange-600 <%= opt_classes %>"
|
|
<%= (opt_val == selected) ? "checked" : "" %>
|
|
<% (opt_attrs || {}).each do |opt_atr_key, opt_atr_value| %>
|
|
<%= opt_atr_key %>="<%= opt_atr_value %>"
|
|
<% end%>
|
|
>
|
|
</div>
|
|
<div class="ml-3 text-sm leading-6">
|
|
<label for="<%= name %>-<%= opt_val %>" class="font-medium text-gray-900"><%== opt_text %></label>
|
|
</div>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
</fieldset>
|
|
<% if error %>
|
|
<p class="text-sm text-red-600 leading-6"><%= error %></p>
|
|
<% end %>
|
|
<% if description %>
|
|
<p class="text-sm text-gray-500 leading-6"><%== description %></p>
|
|
<% end %>
|
|
</div>
|