Class: Admin::Tramway::Event::ParticipantFormFieldForm
- Inherits:
-
Tramway::ExtendedApplicationForm
- Object
- Tramway::ExtendedApplicationForm
- Admin::Tramway::Event::ParticipantFormFieldForm
- Defined in:
- app/forms/admin/tramway/event/participant_form_field_form.rb
Instance Method Summary collapse
-
#initialize(object) ⇒ ParticipantFormFieldForm
constructor
A new instance of ParticipantFormFieldForm.
- #list_field ⇒ Object
- #options ⇒ Object
- #options=(value) ⇒ Object
- #presence_field ⇒ Object
- #select_options ⇒ Object
- #submit(params) ⇒ Object
Constructor Details
#initialize(object) ⇒ ParticipantFormFieldForm
Returns a new instance of ParticipantFormFieldForm.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 7 def initialize(object) super(object).tap do form_properties event: :association, title: :string, description: :string, field_type: :default, options: :text, list_field: :boolean, presence_field: :boolean, position: :numeric, select_options: { type: :string, input_options: { hint: I18n.t('hints.tramway.event.participant_form_field.select_options') } } end end |
Instance Method Details
#list_field ⇒ Object
36 37 38 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 36 def list_field model..present? && model..dig('list_field') == 'true' end |
#options ⇒ Object
48 49 50 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 48 def model.&.to_json end |
#options=(value) ⇒ Object
52 53 54 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 52 def (value) model. = value == '' ? value : JSON.parse(value) end |
#presence_field ⇒ Object
40 41 42 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 40 def presence_field model..present? && model..dig('validations', 'presence') == 'true' end |
#select_options ⇒ Object
44 45 46 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 44 def model..present? && model..dig('collection', 'array')&.join(',') end |
#submit(params) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/forms/admin/tramway/event/participant_form_field_form.rb', line 26 def submit(params) super(params).tap do model. = {} if model. == '' model.&.merge! list_field: (params[:list_field] == '1').to_s model.&.deep_merge! collection: { array: params[:select_options].split(',') || [] } model.&.deep_merge! validations: { presence: (params[:presence_field] == '1').to_s } model.save end end |