From c150c8357898cd3c9c9276be9345c71eb92869c8 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 2 Nov 2022 15:53:17 +0100 Subject: [PATCH] Fix required fields with blank string values --- lib/custom_wizard/validators/update.rb | 2 +- spec/components/custom_wizard/update_validator_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/custom_wizard/validators/update.rb b/lib/custom_wizard/validators/update.rb index d71bded1..631dab55 100644 --- a/lib/custom_wizard/validators/update.rb +++ b/lib/custom_wizard/validators/update.rb @@ -28,7 +28,7 @@ class ::CustomWizard::UpdateValidator file_types = field.file_types format = field.format - if required && !value + if required && !value.present? @updater.errors.add(field_id, I18n.t('wizard.field.required', label: label)) end diff --git a/spec/components/custom_wizard/update_validator_spec.rb b/spec/components/custom_wizard/update_validator_spec.rb index 7caa1784..db5c8ff9 100644 --- a/spec/components/custom_wizard/update_validator_spec.rb +++ b/spec/components/custom_wizard/update_validator_spec.rb @@ -114,6 +114,16 @@ describe CustomWizard::UpdateValidator do ).to eq(I18n.t('wizard.field.required', label: 'Textarea')) end + it 'requires required fields with blank string values' do + @template[:steps][0][:fields][1][:required] = true + CustomWizard::Template.save(@template) + + updater = perform_validation('step_1', step_1_field_2: "") + expect( + updater.errors.messages[:step_1_field_2].first + ).to eq(I18n.t('wizard.field.required', label: 'Textarea')) + end + context "subscription fields" do before do enable_subscription("standard")