Sha256: 6e9d8c43a1fbc02495b5a12e2a56398eb1d5a43421c8f8c53d6d1f883f2401e0

Contents?: true

Size: 982 Bytes

Versions: 8

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

class Tramway::Event::ParticipantFormFieldForm < ::Tramway::Core::ExtendedApplicationForm
  properties :title, :description, :field_type, :options, :position, :list_field
  association :event

  def initialize(object)
    super(object).tap do
      form_properties event: :association,
                      title: :string,
                      description: :string,
                      field_type: :default,
                      options: :text,
                      list_field: :boolean,
                      position: :numeric
    end
  end

  def submit(params)
    super(params).tap do
      model.options = {} if model.options == ''
      model.options&.merge! list_field: (params[:list_field] == '1').to_s
      model.save
    end
  end

  def list_field
    model.options&.dig('list_field') == 'true'
  end

  def options
    model.options&.to_json
  end

  def options=(value)
    super value == '' ? value : JSON.parse(value)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tramway-event-1.9.28.1 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.28 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.27.6 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.27.5 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.27.4 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.27.3 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.27.2 app/forms/tramway/event/participant_form_field_form.rb
tramway-event-1.9.27.1 app/forms/tramway/event/participant_form_field_form.rb