nepttune/base-form-component

v4.3 2018-06-08 10:25 UTC

README

🅱️ Base form component for Nepttune

Packagist Packagist CommitsSinceTag

Code Climate Scrutinizer Code Quality

Functionality

This package introduces base form component with commonly used functionality.

  • Overriden render() method selects template which renders list subcomponent.
  • Precreated createComponentForm method creates and sets up form instance based on class constants. It also sets translator and csrf protection. Inherited class is required to implement modifyForm method where you add custom inputs to your form.
  • Package also inludes some extra validators.
    • Static validator SAME_LENGTH checks wherether two input's value is of same length.
    • Non static validator UNIQUE makes DB select and checks wherether the value is unique.
    • Regex pattern for phone number validaton.

Dependencies

How to use

  • Inherit from \Nepttune\Component\BaseFormComponent.
  • Inject repository class.
  • Override class contants, which define how your list is set up.
    • REDIRECT [string] (default :default) defines destination where to redirect after form success.
    • REDIRECT_ID [bool] (default false) defines whether the id of record should be included as parameter in redirect.
    • SAVE_NEXT [bool] (default false) defines whether the save-next button should be included in form.
    • SAVE_NEXT_REDIRECT [bool] (default :add) defines destination where to redirect after form success for save-next button.
    • SAVE_NEXT_ID [bool] (default false) defines whether the id of record should be included as parameter in redirect for save-next button.
    • SAVE_LIST [array] (default false) defines whether the save-list button should be included in form.
    • SAVE_LIST_REDIRECT [array] (default :list) defines destination where to redirect after form success for save-list button.
    • SAVE_LIST_ID [bool] (default false) defines whether the id of record should be included as parameter in redirect for save-list button.
  • Implement the modifyForm method, where you add other inputs to your form.
  • If needed, override any of the methods to achieve desired behavior.
  • Validators are also defined in class constants $input->addRule(static::VALIDATOR_UNIQUE, static::VALIDATOR_UNIQUE_MSG);.