Esempio n. 1
0
 /**
  * @return string
  */
 public function getControl()
 {
     $control = parent::getControl();
     if ($this->required && !$this->checkbox->isOk()) {
         $control->addAttributes(['required' => TRUE]);
     }
     if ($this->checkbox->isOk()) {
         return $control . $this->checkbox->getControl($this->required);
     }
     return $control;
 }
Esempio n. 2
0
 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param IComponent $form
  * @return void
  */
 protected function attached($form)
 {
     parent::attached($form);
     if ($form instanceof IPresenter) {
         if (isset($form->imageStorage) && $form->imageStorage instanceof IImageStorage) {
             $this->storage = $form->imageStorage;
         } else {
             $this->storage = $form->context->getByType(IImageStorage::class);
         }
         $form = $this->getForm();
         $htmlName = str_replace('[]', '', $this->getHtmlName());
         foreach ($this->defaultValues as $i => $defaultValue) {
             $checkbox = new Checkbox();
             $checkbox->setParent($form, $i);
             $checkbox->setPrepend($htmlName . $i);
             $checkbox->setStorage($this->storage);
             $checkbox->setImageName($defaultValue);
             $this->checkboxes[] = $checkbox;
         }
         if ($this->required && !$this->getCheckboxesFine()) {
             $this->addRule(Form::FILLED, $this->getRequiredMessage());
         }
     }
 }