Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 06d4f041

Přidáno uživatelem Jan Šedivý před téměř 6 roky(ů)

Re #7336 Validace sorteru ve formuláři

Zobrazit rozdíly:

app/AdminModule/component/Surface/SurfaceTypeEditFormFactory.php
41 41
        $form->addText(SurfaceTypeRepository::COLUMN_SURFACE_TYPE, 'Surface Type')
42 42
            ->addRule(Form::REQUIRED, 'Pole %label je povinné.');
43 43

  
44
        $form->addText(SurfaceTypeRepository::COLUMN_SORTER, 'Sorter')
44
        $form->addInteger(SurfaceTypeRepository::COLUMN_SORTER, 'Sorter')
45 45
            ->addRule(Form::REQUIRED, 'Pole %label je povinné.');
46 46

  
47 47
        $form->addSubmit('submit', 'Save');
48 48

  
49
        $form->onValidate[] = [$this, 'formValidate'];
49 50
        $form->onSuccess[] = [$this, 'formSuccess'];
50 51

  
51 52
        if($this->typeId)
......
56 57
        return $form;
57 58
    }
58 59

  
60
    /**
61
     * Validace formuláře
62
     *
63
     * @param Form $form
64
     */
65
    public function formValidate(Form $form)
66
    {
67
        $values = $form->getValues();
68

  
69
        if (!is_int($values->sorter))
70
        {
71
            $form->addError('Sorter must be a number.');
72
        }
73
    }
74

  
59 75
    public function formSuccess(Form $form)
60 76
    {
61 77
        $result = $this->surfaceTypeRepository->save($form->getValues(true), $this->typeId);
app/AdminModule/presenters/SurfacePresenter.php
47 47

  
48 48
    public function actionEditType(int $id)
49 49
    {
50
        if(!$this->surfaceTypeRepository->findRow($id))
51
        {
52
            $this->flashMessage('Surface type was not found.', EFlashMessage::ERROR);
53
            $this->redirect('Surface:');
54
        }
55

  
50 56
        $this->typeId = $id;
51 57
        $this->template->id = $id;
52 58
    }
app/model/repository/Repository.php
81 81
     * Vrací záznam z tabulky podle primárního klíče
82 82
     *
83 83
     * @param int $id
84
     * @return Nette\Database\Table\ActiveRow
84
     * @return boolean|Nette\Database\Table\ActiveRow
85 85
     */
86
    public function findRow(int $id): Nette\Database\Table\ActiveRow
86
    public function findRow(int $id)
87 87
    {
88 88
        return $this->getTable()->get($id);
89 89
    }
app/utils/Form.php
57 57
        return parent::addUpload($name, $label, $multiple)->setHtmlAttribute('class', 'form-control');
58 58
    }
59 59

  
60
    public function addInteger($name, $label = null)
61
    {
62
        return parent::addInteger($name, $label)->setHtmlAttribute('class', 'form-control');
63
    }
64

  
60 65
    protected function beforeRender()
61 66
    {
62 67
        parent::beforeRender();

Také k dispozici: Unified diff