Add validation for form field N/A [SCI-11763]

This commit is contained in:
Anton 2025-04-03 12:42:45 +02:00
parent 5f05c8c21d
commit 5b27e102a9
3 changed files with 16 additions and 2 deletions

View file

@ -1,7 +1,7 @@
<template>
<div>
<button v-if="!disabled" class="btn btn-secondary" @click="rowSelectorOpened = true">
{{ i18n.t('forms.show.add_items') }}
<button v-if="!disabled" class="btn btn-secondary" @click="rowSelectorOpened = true" :disabled="marked_as_na">
{{ i18n.t('forms.show.add_items') }}
<i class="sn-icon sn-icon-right"></i>
</button>
<span class="text-sn-grey-700" v-if="disabled && !field.field_value?.value">

View file

@ -6,6 +6,8 @@ class FormFieldValue < ApplicationRecord
belongs_to :created_by, class_name: 'User'
belongs_to :submitted_by, class_name: 'User'
validate :not_applicable_values
scope :latest, -> { where(latest: true) }
def value=(_)
@ -27,4 +29,12 @@ class FormFieldValue < ApplicationRecord
def name
form_field&.name
end
private
def not_applicable_values
return unless not_applicable
errors.add(:value, :not_applicable) if value.present?
end
end

View file

@ -260,6 +260,10 @@ en:
attributes:
text: Text is too long
position: "Position has already been taken by another item in the checklist"
form_field_value:
attributes:
value:
not_applicable: "Field is not applicable"
storage_location:
missing_position: 'Missing position metadata'
not_uniq_position: 'Position already taken'