From e07cbb649284b78df10ab627c19d5b8de9c0151d Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 23 Apr 2025 12:38:37 +0200 Subject: [PATCH] Fix number block double submission [SCI-11864] --- app/javascript/vue/shared/input_field.vue | 1 - app/models/form_field_value.rb | 7 +++++++ config/locales/en.yml | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/javascript/vue/shared/input_field.vue b/app/javascript/vue/shared/input_field.vue index 677b8a690..a6bd3689c 100644 --- a/app/javascript/vue/shared/input_field.vue +++ b/app/javascript/vue/shared/input_field.vue @@ -30,7 +30,6 @@ :disabled="disabled" :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" - @change="$emit('change', $event.target.value)" class="outline-none shadow-none placeholder:text-sn-grey rounded h-full border border-sn-sleepy-grey bg-white w-full px-4 focus:border-sn-science-blue" :class="{ '!bg-sn-super-light-grey ': disabled, diff --git a/app/models/form_field_value.rb b/app/models/form_field_value.rb index 6bbe53f70..5f8b90109 100644 --- a/app/models/form_field_value.rb +++ b/app/models/form_field_value.rb @@ -7,6 +7,7 @@ class FormFieldValue < ApplicationRecord belongs_to :submitted_by, class_name: 'User' validate :not_applicable_values + validate :uniqueness_latest, if: :latest? scope :latest, -> { where(latest: true) } @@ -37,4 +38,10 @@ class FormFieldValue < ApplicationRecord errors.add(:value, :not_applicable) if value.present? end + + def uniqueness_latest + return unless form_response.form_field_values.exists?(form_field_id: form_field_id, latest: true) + + errors.add(:value, :not_unique_latest) + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 760d0153f..b152748f6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -264,6 +264,7 @@ en: attributes: value: not_applicable: "Field is not applicable" + not_unique_latest: "Latest field value already exists" storage_location: missing_position: 'Missing position metadata' not_uniq_position: 'Position already taken'