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 `||=`.
40 lines
1.5 KiB
Plaintext
40 lines
1.5 KiB
Plaintext
<% name ||= nil
|
|
label ||= nil
|
|
range_labels ||= {}
|
|
value = flash.dig("old", name) || value || 0
|
|
error ||= rodauth.field_error(name) || flash.dig("errors", name)
|
|
description ||= nil
|
|
attributes ||= {}
|
|
extra_class ||= {} %>
|
|
|
|
<div class="space-y-2 text-gray-900">
|
|
<% if label %>
|
|
<label for="<%= name %>" class="block text-sm font-medium leading-6"><%= label %></label>
|
|
<% end %>
|
|
<div class="flex flex-col space-y-2 p-2">
|
|
<input
|
|
id="<%= name %>"
|
|
type="range"
|
|
name="<%= name %>"
|
|
<% if value %>
|
|
value="<%= value %>"
|
|
<% end %>
|
|
class="w-full range-lg h-2 bg-gray-200 accent-orange-600 rounded-lg appearance-none cursor-pointer border-transparent <%=extra_class %> <%= error ? "text-red-900 ring-red-300 focus:ring-red-500" : "text-gray-900 ring-gray-300 focus:ring-orange-600"%>"
|
|
<% attributes.each do |atr_key, atr_value| %>
|
|
<%= atr_key %>="<%= atr_value %>"
|
|
<% end%>
|
|
>
|
|
<ul class="flex justify-between w-full px-[10px] pt-2 sm:pt-8">
|
|
<% range_labels.each do |lbl| %>
|
|
<li class="flex justify-right sm:justify-center relative items-center rotate-90 sm:rotate-0 mb-6 sm:mb-0"><span class="absolute text-center"><%= lbl %></span></li>
|
|
<% end %>
|
|
</ul>
|
|
</div>
|
|
<% if error %>
|
|
<p class="text-sm text-red-600 leading-6" id="<%= name %>-error"><%= error %></p>
|
|
<% end %>
|
|
<% if description %>
|
|
<p class="text-sm text-gray-500 leading-6" id="<%= name %>-description"><%== description %></p>
|
|
<% end %>
|
|
</div>
|