adjust condition
This commit is contained in:
@@ -1244,17 +1244,31 @@ export default {
|
|||||||
} else if (['equal', 'contains'].includes(condition.action) && field) {
|
} else if (['equal', 'contains'].includes(condition.action) && field) {
|
||||||
if (field.options) {
|
if (field.options) {
|
||||||
const option = field.options.find((o) => o.uuid === condition.value)
|
const option = field.options.find((o) => o.uuid === condition.value)
|
||||||
const values = [this.values[condition.field_uuid] ?? defaultValue].flat()
|
|
||||||
|
|
||||||
return values.includes(this.optionValue(option, field.options.indexOf(option)))
|
if (option) {
|
||||||
|
const values = [this.values[condition.field_uuid] ?? defaultValue].flat()
|
||||||
|
|
||||||
|
return values.includes(this.optionValue(option, field.options.indexOf(option)))
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return [this.values[condition.field_uuid] ?? defaultValue].flat().includes(condition.value)
|
return [this.values[condition.field_uuid] ?? defaultValue].flat().includes(condition.value)
|
||||||
}
|
}
|
||||||
} else if (['not_equal', 'does_not_contain'].includes(condition.action) && field) {
|
} else if (['not_equal', 'does_not_contain'].includes(condition.action) && field) {
|
||||||
const option = field.options.find((o) => o.uuid === condition.value)
|
if (field.options) {
|
||||||
const values = [this.values[condition.field_uuid] ?? defaultValue].flat()
|
const option = field.options.find((o) => o.uuid === condition.value)
|
||||||
|
|
||||||
return !values.includes(this.optionValue(option, field.options.indexOf(option)))
|
if (option) {
|
||||||
|
const values = [this.values[condition.field_uuid] ?? defaultValue].flat()
|
||||||
|
|
||||||
|
return !values.includes(this.optionValue(option, field.options.indexOf(option)))
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,21 +318,38 @@ module Submitters
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check_field_condition(condition, submitter_values, fields_uuid_index)
|
def check_field_condition(condition, submitter_values, fields_uuid_index)
|
||||||
|
value = submitter_values[condition['field_uuid']]
|
||||||
|
|
||||||
case condition['action']
|
case condition['action']
|
||||||
when 'empty', 'unchecked'
|
when 'empty', 'unchecked'
|
||||||
submitter_values[condition['field_uuid']].blank?
|
value.blank?
|
||||||
when 'not_empty', 'checked'
|
when 'not_empty', 'checked'
|
||||||
submitter_values[condition['field_uuid']].present?
|
value.present?
|
||||||
when 'equal', 'contains'
|
when 'equal', 'contains'
|
||||||
field = fields_uuid_index[condition['field_uuid']]
|
field = fields_uuid_index[condition['field_uuid']]
|
||||||
|
|
||||||
|
return true unless field
|
||||||
|
|
||||||
|
values = Array.wrap(value)
|
||||||
|
|
||||||
|
return values.include?(condition['value']) unless field['options']
|
||||||
|
|
||||||
option = field['options'].find { |o| o['uuid'] == condition['value'] }
|
option = field['options'].find { |o| o['uuid'] == condition['value'] }
|
||||||
values = Array.wrap(submitter_values[condition['field_uuid']])
|
|
||||||
|
return false unless option
|
||||||
|
|
||||||
values.include?(option['value'].presence || "#{I18n.t('option')} #{field['options'].index(option) + 1}")
|
values.include?(option['value'].presence || "#{I18n.t('option')} #{field['options'].index(option) + 1}")
|
||||||
when 'not_equal', 'does_not_contain'
|
when 'not_equal', 'does_not_contain'
|
||||||
field = fields_uuid_index[condition['field_uuid']]
|
field = fields_uuid_index[condition['field_uuid']]
|
||||||
|
|
||||||
|
return true unless field
|
||||||
|
return false unless field['options']
|
||||||
|
|
||||||
option = field['options'].find { |o| o['uuid'] == condition['value'] }
|
option = field['options'].find { |o| o['uuid'] == condition['value'] }
|
||||||
values = Array.wrap(submitter_values[condition['field_uuid']])
|
|
||||||
|
return false unless option
|
||||||
|
|
||||||
|
values = Array.wrap(value)
|
||||||
|
|
||||||
values.exclude?(option['value'].presence || "#{I18n.t('option')} #{field['options'].index(option) + 1}")
|
values.exclude?(option['value'].presence || "#{I18n.t('option')} #{field['options'].index(option) + 1}")
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user