Sha256: 2872059d406b954342452ae75a6136d99d88a99ad666d35378932cc1fd48f1c3

Contents?: true

Size: 901 Bytes

Versions: 29

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

class Tramway::Event::ParticipantExtendedFormCreator < Tramway::Core::FormCreator
  def self.create_form_class(uuid, event, **simple_properties)
    class_name = "ParticipantExtendedForm#{uuid.gsub('-', '')}"
    properties = event.participant_form_fields.inputs_list.reduce({}) do |hash, field|
      hash.merge! field.title.to_sym => {
        object: field,
        validates: build_validations(field)
      }
    end
    if simple_properties.keys.any?
      ::Tramway::Core::ExtendableForm.new(class_name, simple_properties: simple_properties, **properties)
    else
      ::Tramway::Core::ExtendableForm.new(class_name, **properties)
    end
  end

  def self.build_validations(field)
    case field.field_type
    when 'checkbox'
      field.validations.except('presence').deep_merge! inclusion: { in: ['true'] }
    else
      field.validations
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
tramway-event-1.12.9.1 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.9 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.8.2 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.8.1 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.8 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.7 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.6.4 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.6.3 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.6.2 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.6 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.5 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.4 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.10 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.9 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.8 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.7 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.6 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.5 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.4 app/forms/tramway/event/participant_extended_form_creator.rb
tramway-event-1.12.3.3 app/forms/tramway/event/participant_extended_form_creator.rb