forked from fixin.me/fixin.me
Measurement form based on select-styled <details>
This commit is contained in:
@@ -75,12 +75,11 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def number_field(method, options = {})
|
||||
value = object.public_send(method)
|
||||
if value.is_a?(BigDecimal)
|
||||
options[:value] = value.to_scientific
|
||||
type = object.class.type_for_attribute(method)
|
||||
options[:step] ||= BigDecimal(10).power(-type.scale)
|
||||
options[:max] ||= BigDecimal(10).power(type.precision - type.scale) -
|
||||
attr_type = object.type_for_attribute(method)
|
||||
if attr_type.type == :decimal
|
||||
options[:value] = object.public_send(method)&.to_scientific
|
||||
options[:step] ||= BigDecimal(10).power(-attr_type.scale)
|
||||
options[:max] ||= BigDecimal(10).power(attr_type.precision - attr_type.scale) -
|
||||
options[:step]
|
||||
options[:min] = options[:min] == :step ? options[:step] : options[:min]
|
||||
options[:min] ||= -options[:max]
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
module QuantitiesHelper
|
||||
def quantities_check_boxes
|
||||
# Closing <details> on focusout event depends on relatedTarget for internal
|
||||
# actions being non-null. To ensure this, all top-layer elements of
|
||||
# ::details-content must accept focus, e.g. <label> needs tabindex="-1" */
|
||||
collection_check_boxes(nil, :quantity, @quantities, :id, :to_s_with_depth,
|
||||
include_hidden: false) do |b|
|
||||
content_tag :li, b.label(tabindex: -1) { b.check_box + b.text }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user