0
0
Fork 0

Added validator for extra profile field values with empty name (#33421)

This commit is contained in:
Tim Rogers 2025-01-04 13:42:27 -06:00 committed by GitHub
parent 9b82bedc6f
commit 3bdfa3eb4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 1 deletions

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class EmptyProfileFieldNamesValidator < ActiveModel::Validator
def validate(account)
return if account.fields.empty?
account.errors.add(:fields, :fields_with_values_missing_labels) if fields_with_values_missing_names?(account)
end
private
def fields_with_values_missing_names?(account)
account.fields.any? { |field| field.name.blank? && field.value.present? }
end
end