diff --git a/CHANGELOG.md b/CHANGELOG.md index 2df0968..30b8d6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [3.1.0] +## [4.0.0] - Form nows register element class, instead of using hardcoded string. - Form has new `registerType` method to register new custom elements. `getType(string $name)` and `getTypes()` can be used to get the class for a type (eg. 'text', 'select', etc.) abd a list of types. `removeType` will unregister a type. - Form still fallback to `Text` type if type is not found, but this can now be changed with `getDefaultType` and `setDefaultType`. @@ -111,7 +111,7 @@ The custom `RequestSchema` have been removed. Instead of building the form direc ### Security --> -[3.1.0]: https://github.com/lcharette/UF_FormGenerator/compare/3.0.0...3.1.0 +[4.0.0]: https://github.com/lcharette/UF_FormGenerator/compare/3.0.0...4.0.0 [3.0.0]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.10...3.0.0 [2.2.10]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.9...2.2.10 [2.2.9]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.8...2.2.9 diff --git a/README.md b/README.md index cbc5547..4dfdcf9 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,27 @@ # Form Generator Sprinkle for [UserFrosting 4](https://www.userfrosting.com) -[![Latest Version](https://img.shields.io/github/release/lcharette/UF_FormGenerator.svg)](https://github.com/lcharette/UF_FormGenerator/releases) +[![Donate][kofi-badge]][kofi] +[![Latest Version][releases-badge]][releases] +[![UserFrosting Version][uf-version]][uf] [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) -[![UserFrosting Version](https://img.shields.io/badge/UserFrosting->=%204.2-brightgreen.svg)](https://github.com/userfrosting/UserFrosting) -[![Build Status](https://travis-ci.org/lcharette/UF_FormGenerator.svg?branch=master)](https://travis-ci.org/lcharette/UF_FormGenerator) -[![StyleCI](https://github.styleci.io/repos/68563337/shield?branch=master&style=flat)](https://github.styleci.io/repos/68563337) -[![Codecov](https://codecov.io/gh/lcharette/UF_FormGenerator/branch/master/graph/badge.svg)](https://codecov.io/gh/lcharette/UF_FormGenerator) -[![Donate](https://img.shields.io/badge/Donate-Buy%20Me%20a%20Coffee-blue.svg)](https://ko-fi.com/A7052ICP) - -This Sprinkle provides helper classes, Twig template and JavaScript plugins to generate HTML forms, modals and confirm modal bases on UserFrosting/[validation schemas](https://learn.userfrosting.com/routes-and-controllers/client-input/validation). - -> This version requires UserFrosting 4.2 and up. Check out [FormGenerator 2.2 for UF 4.1 support](#versions-and-userfrosting-support). +[![Travis][travis-badge]][travis] +[![Codecov][codecov-badge]][codecov] +[![StyleCI][styleci-badge]][styleci] + +[kofi]: https://ko-fi.com/A7052ICP +[kofi-badge]: https://img.shields.io/badge/Donate-Buy%20Me%20a%20Coffee-blue.svg +[releases]: https://github.com/lcharette/UF_FormGenerator/releases +[releases-badge]: https://img.shields.io/github/release/lcharette/UF_FormGenerator.svg +[uf-version]: https://img.shields.io/badge/UserFrosting->=%204.3-brightgreen.svg +[uf]: https://github.com/userfrosting/UserFrosting +[travis]: https://travis-ci.org/lcharette/UF_FormGenerator +[travis-badge]: https://travis-ci.org/lcharette/UF_FormGenerator.svg?branch=master +[codecov]: https://codecov.io/gh/lcharette/UF_FormGenerator +[codecov-badge]: https://codecov.io/gh/lcharette/UF_FormGenerator/branch/master/graph/badge.svg +[styleci]: https://styleci.io/repos/68563337 +[styleci-badge]: https://styleci.io/repos/68563337/shield?branch=master&style=flat + +This Sprinkle provides helper classes, Twig template and JavaScript plugins to generate HTML forms, modals and confirm modal bases on UserFrosting [validation schemas](https://learn.userfrosting.com/routes-and-controllers/client-input/validation). # Help and Contributing @@ -18,21 +29,24 @@ If you need help using this sprinkle or found any bug, feels free to open an iss # Versions and UserFrosting support -FormGenerator version goes up one major version (2.x.x -> 3.x.x) when moving to a new minor or major version (4.1.x -> 4.2.x) of UserFrosting is released. Breaking changes inside FormGenerator itself trigger a new minor version (FG 2.0.x -> 2.1.x) while normal path makes FormGenerator to go up one revision number (2.1.2 -> 2.1.3). - | UserFrosting Version | FormGenerator Version | -|----------------------|-----------------------| -| 4.2.x | 3.x.x | -| 4.1.x | [2.x.x] | -| < 4.0.x | No Support | +| :------------------: | :-------------------: | +| 4.4.x | 4.x.x | +| 4.3.x | [3.0.x] & 4.0.x | +| 4.2.x | [3.0.x] | +| 4.1.x | [2.0.x] | +| 4.0.x | No Support | + +[3.0.x]: https://github.com/lcharette/UF_FormGenerator/tree/3.0#form-generator-sprinkle-for-userfrosting-4 +[2.0.x]: https://github.com/lcharette/UF_FormGenerator/tree/2.2#form-generator-sprinkle-for-userfrosting-4 # Installation -Edit UserFrosting `app/sprinkles.json` file and add the following to the `require` list : `"lcharette/uf_formgenerator": "^3.0.0"`. Also add `FormGenerator` to the `base` list. For example: +Edit UserFrosting `app/sprinkles.json` file and add the following to the `require` list : `"lcharette/uf_formgenerator": "^4.0.0"`. Also add `FormGenerator` to the `base` list. For example: -``` +```json { "require": { - "lcharette/uf_formgenerator": "^3.0.0" + "lcharette/uf_formgenerator": "^4.0.0" }, "base": [ "core", @@ -45,6 +59,10 @@ Edit UserFrosting `app/sprinkles.json` file and add the following to the `requir Run `composer update` then `php bakery bake` to install the sprinkle. +# Working example + +See the [UF_FormGeneratorExample](https://github.com/lcharette/UF_FormGeneratorExample) repo for an example of the FormGenerator full code. + # Features and usage Before starting with _FormGenerator_, you should read the main UserFrosting guide to familiarize yourself with _validation schemas_: (https://learn.userfrosting.com/routes-and-controllers/client-input/validation). @@ -54,7 +72,7 @@ This sprinkle uses the `schemas` used by UserFrosting to validate form data to b For example, here's a simple `schema` used to validate a form used to create a `project`. The form will contain a `name`, `description` and `status` fields. -``` +```json { "name" : { "validators" : { @@ -88,7 +106,7 @@ For example, here's a simple `schema` used to validate a form used to create a ` At this point, with typical UserFrosting setup, you would be going into your controller and Twig files to manually create your HTML form. This can be easy if you have a two or three fields, but can be a pain with a dozen fields and more. This is where FormGenerator steps in with the use of a new `form` attribute. Let's add it to our `project` form : -``` +```json { "name" : { "validators" : { @@ -142,7 +160,7 @@ At this point, with typical UserFrosting setup, you would be going into your con Let's look closer at the `name` field : -``` +```json "form" : { "type" : "text", "label" : "PROJECT.NAME", @@ -170,7 +188,7 @@ First thing to do is add FormGenerator's `Form` class to your "use" list : `use UserFrosting\Sprinkle\FormGenerator\Form;` Next, where you load the schema and setup the `validator`, you simply add the new Form creation: -``` +```php // Load validator rules $schema = new RequestSchema("schema://project.json"); $validator = new JqueryValidationAdapter($schema, $this->ci->translator); @@ -182,7 +200,7 @@ $form = new Form($schema, $project); In this example, `$project` can contain the default (or current value) of the fields. A data collection fetched from the database with eloquent can also be passed directly. That second argument can also be omitted to create an empty form. Last thing to do is send the fields to Twig. In the list of retuned variables to the template, add the `fields` variable: -``` +```php $this->ci->view->render($response, "pages/myPage.html.twig", [ "fields" => $form->generate(), "validators" => $validator->rules('json', true) @@ -194,7 +212,7 @@ $this->ci->view->render($response, "pages/myPage.html.twig", [ Now it's time to display the form in `myPage.html.twig` ! -``` +```html