nepttune/base-form-component

Base form component for Nepttune

v5.0.1 2018-12-07 23:13 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 form 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.
    • SAVE_NEXT [bool] (default false) defines whether the save-next button should be included in form.
    • SAVE_LIST [array] (default false) defines whether the save-list button should be included in form.
  • 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);.