aipng/forms

Reusable form control.

0.4 2019-11-11 14:45 UTC

This package is auto-updated.

Last update: 2020-03-11 15:43:17 UTC


README

"Form as a component" control. Form should be defined in createComponentForm method.

Simple structure:

/my-app/src/
    templates/MyForm.latte
    MyForm.php
    MyForm.latte

MyForm.latte - customized form template (when needed)

{form form}
    manual rendering of form controls
    ...
{/form}

MyForm.php

final class MyForm extends \AipNg\Forms\BaseFormControl
{

  public function createComponentForm(): \Nette\Application\UI\Form
  {
    $form = ...
    
    return $form;
  }

}

Usage in presenter

//  in presenter

class MyPresenter
  public function createComponentMyForm()
  {
    return new MyForm;
  }

  public function actionEdit()
  {
    $this['myForm']->setDefaults([
      ...
    ]);
  }

Latte

Input description macro helps to show control's description in template when using manual rendering.

Register in config.neon:

latte:
    macros:
        - AipNg\Latte\Macro\InputDescriptionMacro::register

Just use anywhere in form template

{inputDescription $controlName}