Esempio n. 1
0
 public function getSelectField($renderApi, $unit, $fieldId, $postRequestValue = null)
 {
     $inputName = strlen($renderApi->getFormValue($unit, 'inputName')) > 0 ? $renderApi->getFormValue($unit, 'inputName') : $fieldId;
     $formField = new \SelectField();
     $formField->getElementProperties()->addAttribute("name", $inputName);
     $formField->getElementProperties()->addAttribute("id", $fieldId);
     $listOptions = $this->listOptions->getListOptions($renderApi, $unit);
     if ($listOptions->hasOptions()) {
         foreach ($listOptions->getOptions() as $option) {
             /* @var $option \Option */
             $optionField = new \OptionField();
             $optionField->setContent($option->getName());
             $elementProperties = $optionField->getElementProperties();
             $elementProperties->addAttribute("value", $option->getValue());
             if (is_null($postRequestValue) && $option->isChecked() || $postRequestValue === $option->getValue()) {
                 $elementProperties->addAttribute("selected", null);
             }
             $formField->add($optionField);
         }
     }
     if ($this->formSubmit->isValid($renderApi, $unit) && !$this->isValidValue($unit, $postRequestValue)) {
         $formField->getElementProperties()->addClass('vf__error');
     }
     return $formField;
 }