Previously, this would assume a given type, and likely raise NoMethodError if the type was not what was expected. If there is a typecast error when rendering the validation failure template, display a simple error page. This should only happen if a user monkeys around with a form parameter before submitting the request. This uses a new feature in the Roda typecast_params plugin, so update to the latest Roda commit.
42 lines
1.8 KiB
Plaintext
42 lines
1.8 KiB
Plaintext
<%# locals: (name:, label:, options:, attributes:) %>
|
|
<% selected = flash.dig("old", name) || typecast_body_params.str(name) || selected
|
|
error = flash.dig("errors", name)
|
|
is_content_array = options[0][1].is_a?(Array) %>
|
|
|
|
<div class="space-y-2">
|
|
<label class="text-sm font-medium leading-6 text-gray-900"><%= label %></label>
|
|
<fieldset class="radio-small-cards">
|
|
<legend class="sr-only"><%= label %></legend>
|
|
<div class="grid gap-3 grid-cols-[repeat(auto-fill,minmax(285px,1fr))]">
|
|
<% options.each_with_index do |(opt_val, opt_text, opt_classes, opt_attrs), idx| %>
|
|
<label class="<%= opt_classes %>">
|
|
<input
|
|
type="radio"
|
|
name="<%= name %>"
|
|
value="<%= opt_val %>"
|
|
class="peer sr-only"
|
|
<%== html_attrs(**attributes, **opt_attrs) %>
|
|
>
|
|
<% if is_content_array %>
|
|
<span class="radio-small-card justify-between p-4">
|
|
<span class="flex flex-col">
|
|
<span class="text-md font-semibold"><%= opt_text[0] %></span>
|
|
<span class="text-sm opacity-80"><span class="block sm:inline"><%= opt_text[1] %></span></span>
|
|
</span>
|
|
<span class="mt-2 flex text-sm sm:ml-4 sm:mt-0 sm:flex-col sm:text-right">
|
|
<span class="font-medium"><%= opt_text[2] %></span>
|
|
<span class="ml-1 opacity-50 sm:ml-0"><%= opt_text[3] %></span>
|
|
</span>
|
|
</span>
|
|
<% else %>
|
|
<span class="radio-small-card justify-center p-3 text-sm font-semibold"><%= opt_text %></span>
|
|
<% end %>
|
|
</label>
|
|
<% end %>
|
|
</div>
|
|
</fieldset>
|
|
<% if error %>
|
|
<p class="text-sm text-red-600 leading-6" id="<%= name %>-error"><%= error %></p>
|
|
<% end %>
|
|
</div>
|