Class: Decidim::Templates::Admin::ProposalAnswerTemplateForm

Inherits:
TemplateForm show all
Defined in:
decidim-templates/app/forms/decidim/templates/admin/proposal_answer_template_form.rb

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods included from Decidim::TranslatableAttributes

#attachment?, #default_locale?

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#component_has_been_selectedObject



30
31
32
# File 'decidim-templates/app/forms/decidim/templates/admin/proposal_answer_template_form.rb', line 30

def component_has_been_selected
  errors.add(:select_component, :blank) if select_component
end

#map_model(model) ⇒ Object



14
15
16
17
# File 'decidim-templates/app/forms/decidim/templates/admin/proposal_answer_template_form.rb', line 14

def map_model(model)
  self.proposal_state_id = model.field_values["proposal_state_id"]&.to_i
  self.component_constraint = model.templatable&.id
end

#proposal_state_id_is_validObject



23
24
25
26
27
28
# File 'decidim-templates/app/forms/decidim/templates/admin/proposal_answer_template_form.rb', line 23

def proposal_state_id_is_valid
  if Decidim::Proposals::ProposalState.where(decidim_component_id: component_constraint).find_by(id: proposal_state_id).blank?
    errors.add(:proposal_state_id,
               :blank)
  end
end

#skip_name_validationObject



19
20
21
# File 'decidim-templates/app/forms/decidim/templates/admin/proposal_answer_template_form.rb', line 19

def skip_name_validation
  select_component
end