Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: required fields with blank string values #208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/custom_wizard/validators/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def validate_field(field)
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

Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.0.7
# version: 2.0.8
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
# url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: [email protected]
Expand Down
10 changes: 10 additions & 0 deletions spec/components/custom_wizard/update_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ def perform_validation(step_id, submission)
).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")
Expand Down