add number conditions

This commit is contained in:
Pete Matsyburka
2026-01-31 08:39:32 +02:00
parent 56d4fe7fa9
commit d7682f4ebd
5 changed files with 78 additions and 5 deletions
+19 -4
View File
@@ -317,17 +317,33 @@ module Submitters
end.exclude?(false)
end
# rubocop:disable Metrics
def check_field_condition(condition, submitter_values, fields_uuid_index)
value = submitter_values[condition['field_uuid']]
field = fields_uuid_index[condition['field_uuid']]
case condition['action']
when 'empty', 'unchecked'
value.blank?
when 'not_empty', 'checked'
value.present?
when 'equal', 'contains'
field = fields_uuid_index[condition['field_uuid']]
when ->(action) { action == 'equal' && field&.dig('type') == 'number' }
return false if value.blank? || condition['value'].blank?
(value.to_f - condition['value'].to_f).abs < Float::EPSILON
when ->(action) { action == 'not_equal' && field&.dig('type') == 'number' }
return false if value.blank? || condition['value'].blank?
(value.to_f - condition['value'].to_f).abs > Float::EPSILON
when 'greater_than'
return false if field.nil? || value.blank? || condition['value'].blank?
value.to_f > condition['value'].to_f
when 'less_than'
return false if field.nil? || value.blank? || condition['value'].blank?
value.to_f < condition['value'].to_f
when 'equal', 'contains'
return true unless field
values = Array.wrap(value)
@@ -340,8 +356,6 @@ module Submitters
values.include?(option['value'].presence || "#{I18n.t('option')} #{field['options'].index(option) + 1}")
when 'not_equal', 'does_not_contain'
field = fields_uuid_index[condition['field_uuid']]
return true unless field
return false unless field['options']
@@ -356,6 +370,7 @@ module Submitters
true
end
end
# rubocop:enable Metrics
def replace_default_variables(value, attrs, submission, with_time: false)
return value if value.in?([true, false]) || value.is_a?(Numeric) || value.is_a?(Array)