Files
ubicloud/views/components/form/checkbox.erb
Jeremy Evans dd9a51da2e Fix required="true" attributes
Add a custom validator looking for {required,checked}={true,false}
attributes. This found numerous cases.

Add an html_attrs method that handles required/checked attributes
properly, skipping them if the value is false, and using them
without a value if the value is true.

Change all attribute handling to use html_attrs to fix the issue.
2025-05-13 06:24:13 +09:00

35 lines
1.2 KiB
Plaintext

<%# locals: (name: nil, id_prefix: nil, label: nil, options: {}, description: nil, attributes: {}) %>
<div class="space-y-2 text-gray-900">
<% if label %>
<label class="block text-sm font-medium leading-6"><%== label %></label>
<% end %>
<fieldset>
<div class="space-y-5">
<% options.each_with_index do |(opt_val, opt_text, opt_classes, opt_attrs), idx| %>
<% id = "#{id_prefix}#{name}-#{opt_val}-#{idx}" %>
<div class="relative flex items-start <%= opt_classes %>">
<div class="flex h-6 items-center">
<input
id="<%= id %>"
name="<%= name %>"
type="checkbox"
value="<%= opt_val %>"
class="h-4 w-4 rounded border-gray-300 text-orange-600 focus:ring-orange-600"
<%== html_attrs(opt_attrs || {}) %>
>
</div>
<% if opt_text %>
<div class="ml-3 text-sm leading-6">
<label for="<%= id %>" class="font-medium text-gray-900"><%== opt_text %></label>
</div>
<% end %>
</div>
<% end %>
</div>
</fieldset>
<% if description %>
<p class="text-sm text-gray-500 leading-6"><%== description %></p>
<% end %>
</div>