diff --git a/.travis.yml b/.travis.yml index d398931..8b59032 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ php: - 7 - 7.1 - 7.2 + - 7.3 cache: directories: @@ -38,4 +39,4 @@ after_failure: after_success: - cd app/sprinkles/FormGenerator/ - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file + - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0975d22..3acf325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,51 +1,55 @@ # Change Log -## 2.2.10 +## [3.0.0] +- Added `successCallback` option +- Support for UserFrosting 4.2 + +## [2.2.10] - Added support for Repository -## 2.2.9 +## [2.2.9] - Fix issue when setting data that is a collection - `formSuccess` and `confirmSuccess` events now include the request data as a second argument -## 2.2.8 +## [2.2.8] - Fix icon in textarea macro -## 2.2.7 +## [2.2.7] - Added `modal-large` template file. -## 2.2.6 +## [2.2.6] - Fix issue with `binary` checkbox tests. - Fix Text input style when no icon is added -## 2.2.5 +## [2.2.5] - Added `binary` option for checkbox to disable UF binary checkbox system (bool; default true). -## 2.2.4 +## [2.2.4] - Add necessary HTML to disable submit and cancel button in modal form. -## 2.2.3 +## [2.2.3] - New `$form->setOptions` function to set options of a select element. Shortcut for using `setInputArgument` and `setValue`. -## 2.2.2 +## [2.2.2] - Fix issue with error alert no displaying on confirmation dialog -## 2.2.1 +## [2.2.1] - Initialize ufAlert if not already done - Autofocus first form field when modal is displayed -## 2.2.0 +## [2.2.0] - Refactored the javascript plugin - Added new events - Added new `redirectAfterSuccess` boolean option -## 2.1.2 +## [2.1.2] - Fix warning with select macro -## 2.1.1 +## [2.1.1] - Fix issue with the select macro - Renamed macro templates with the `*.html.twig` extension -## 2.1.0 +## [2.1.0] - Completely refactored how form fields are parsed, including how default value are defined. Each input type now defines it's own class for defining default values and transforming some input. - Twig templates updated to reflect the new parser. - Twig macros changed from `*.generate(name, value)` to `*.generate(input)`. @@ -64,15 +68,49 @@ } ``` -## 2.0.0 +## [2.0.0] - Updated for UserFrosting v4.1.x The custom `RequestSchema` have been removed. Instead of building the form directly on the schema using `$schema->initForm()`, you now create a new Form using `$form = new Form($schema)` and go on from there. Handling complex schema can now be done using the new loader system from UF 4.1. `$schema->generateForm();` has also been changed to `$form->generate();`. -## 1.0.1 +## [1.0.1] - Bug fixes ## 1.0.0 - Initial release + + + +[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 +[2.2.8]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.7...2.2.8 +[2.2.7]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.6...2.2.7 +[2.2.6]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.5...2.2.6 +[2.2.5]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.4...2.2.5 +[2.2.4]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.3...2.2.4 +[2.2.3]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.2...2.2.3 +[2.2.2]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.1...2.2.2 +[2.2.1]: https://github.com/lcharette/UF_FormGenerator/compare/2.2.0...2.2.1 +[2.2.0]: https://github.com/lcharette/UF_FormGenerator/compare/2.1.2...2.2.0 +[2.1.2]: https://github.com/lcharette/UF_FormGenerator/compare/2.1.1...2.1.2 +[2.1.1]: https://github.com/lcharette/UF_FormGenerator/compare/2.1.0...2.1.1 +[2.1.0]: https://github.com/lcharette/UF_FormGenerator/compare/2.0.0...2.1.0 +[2.0.0]: https://github.com/lcharette/UF_FormGenerator/compare/1.0.1...2.0.0 +[1.0.1]: https://github.com/lcharette/UF_FormGenerator/compare/1.0.0...1.0.1 diff --git a/README.md b/README.md index deb8e61..cbc5547 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,38 @@ # Form Generator Sprinkle for [UserFrosting 4](https://www.userfrosting.com) -[![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)](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) [![UserFrosting Version](https://img.shields.io/badge/UserFrosting->=%204.1-brightgreen.svg)](https://github.com/userfrosting/UserFrosting) [![Donate](https://img.shields.io/badge/Donate-Buy%20Me%20a%20Coffee-brightgreen.svg)](https://ko-fi.com/A7052ICP) +[![Latest Version](https://img.shields.io/github/release/lcharette/UF_FormGenerator.svg)](https://github.com/lcharette/UF_FormGenerator/releases) +[![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 only works with UserFrosting 4.1.x ! +> This version requires UserFrosting 4.2 and up. Check out [FormGenerator 2.2 for UF 4.1 support](#versions-and-userfrosting-support). # Help and Contributing If you need help using this sprinkle or found any bug, feels free to open an issue or submit a pull request. You can also find me on the [UserFrosting Chat](https://chat.userfrosting.com/) most of the time for direct support. +# 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 | + # Installation -Edit UserFrosting `app/sprinkles.json` file and add the following to the `require` list : `"lcharette/uf_formgenerator": "^2.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": "^3.0.0"`. Also add `FormGenerator` to the `base` list. For example: ``` { "require": { - "lcharette/uf_formgenerator": "^2.0.0" + "lcharette/uf_formgenerator": "^3.0.0" }, "base": [ "core", @@ -163,7 +179,7 @@ $validator = new JqueryValidationAdapter($schema, $this->ci->translator); $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 omited to create an empty form. +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: ``` @@ -228,7 +244,7 @@ So at this point you have a controller that displays the modal at a `/path/to/co First, define a link or a button that will call the modal when clicked. For example : ``` - + ``` The important part here is the `data-formUrl` attribute. This is the route that will load your form. `js-displayForm` is used here to bind the button to the action. @@ -252,8 +268,7 @@ Let's look at a delete button / confirmation for our `project` : data-confirm-title="Delete project ?" data-confirm-message="Are you sure you want to delete this project?" data-confirm-button="Yes, delete project" - data-post-url="/porject/delete" -data-toggle="modal"> Delete + data-post-url="/project/delete"> Delete ``` (Note that content of data attributes can be translation keys) @@ -272,7 +287,7 @@ By default, the `formGenerator` plugin will bind a **confirmation modal** to eve #### setInputArgument -Form field input attributes can also be added or edited from PHP. This can be usefull when dynamically defining a Select input options. To do this, simply use the `setInputArgument($inputName, $property, $data)` method. For example, to add a list to a `clients` select : +Form field input attributes can also be added or edited from PHP. This can be useful when dynamically defining a Select input options. To do this, simply use the `setInputArgument($inputName, $property, $data)` method. For example, to add a list to a `clients` select : ``` // Get clients from the db model @@ -317,7 +332,7 @@ The following options are available: Just pass an object with those - `mainAlertElement` (jQuery element). The element on the main page where the main alerts will be displayed. Default to `$('#alerts-page')`. - - `redirectAfterSuccess` (bool). If set to true, the page will reload when the form submission or confirmation is succesful. Default to `true`. + - `redirectAfterSuccess` (bool). If set to true, the page will reload when the form submission or confirmation is successful. Default to `true`. Example: ``` @@ -348,6 +363,9 @@ See the [UF_FormGeneratorExample](https://github.com/lcharette/UF_FormGeneratorE FormGenerator comes with some unit tests. Before submitting a new Pull Request, you need to make sure all tests are a go. With the sprinkle added to your UserFrosting installation, simply execute the `php bakery test` command to run the tests. -# Licence +# License + +By [Louis Charette](https://github.com/lcharette). Copyright (c) 2019, free to use in personal and commercial software as per the MIT license. + -By [Louis Charette](https://github.com/lcharette). Copyright (c) 2017, free to use in personal and commercial software as per the MIT license. +[2.x.x]: https://github.com/lcharette/UF_FormGenerator/tree/2.2.10#form-generator-sprinkle-for-userfrosting-4 \ No newline at end of file diff --git a/asset-bundles.json b/asset-bundles.json index b763d55..57c5f0f 100644 --- a/asset-bundles.json +++ b/asset-bundles.json @@ -2,7 +2,7 @@ "bundle": { "js/FormGenerator": { "scripts": [ - "vendor/bootstrap3-typeahead/bootstrap3-typeahead.js", + "vendor/bootstrap-3-typeahead/bootstrap3-typeahead.js", "js/widget-formGenerator.js" ], "options": { diff --git a/assets/js/widget-formGenerator.js b/assets/js/widget-formGenerator.js index 52743f6..8b5c87c 100644 --- a/assets/js/widget-formGenerator.js +++ b/assets/js/widget-formGenerator.js @@ -19,7 +19,8 @@ DEBUG : false, mainAlertElement : $('#alerts-page'), redirectAfterSuccess : true, - autofocusModalElement : true + autofocusModalElement : true, + successCallback : function(data) {} }; // Constructor @@ -135,6 +136,9 @@ // Trigger success event $(button).trigger("formSuccess." + this._name, data); + // Use the callback + this.settings.successCallback(data); + // Refresh page or close modal if (this.settings.redirectAfterSuccess) { window.location.reload(true); @@ -227,6 +231,9 @@ // Trigger success event $(button).trigger("confirmSuccess." + this._name, data); + // Use the callback + this.settings.successCallback(data); + // Refresh page or close modal if (this.settings.redirectAfterSuccess) { diff --git a/bower.json b/bower.json deleted file mode 100644 index 723b5cc..0000000 --- a/bower.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "formgenerator-assets", - "version": "0.0.1", - "homepage": "https://github.com/lcharette/UF_FormGenerator", - "authors": [ - "lcharette" - ], - "moduleType": [ - "node" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "assets/vendor", - "examples", - "demo-resources", - "demo", - "test", - "tests" - ], - "dependencies": { - "bootstrap3-typeahead": "~3.1.0" - }, - "resolutions": { - "jquery": ">= 2.2.4", - "bootstrap": "3.x" - } -} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6bdc4bd --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "bootstrap-3-typeahead": "~4.0.2" + } +} diff --git a/templates/FormGenerator/FormGenerator.html.twig b/templates/FormGenerator/FormGenerator.html.twig index c902064..ccf25c4 100644 --- a/templates/FormGenerator/FormGenerator.html.twig +++ b/templates/FormGenerator/FormGenerator.html.twig @@ -12,7 +12,7 @@ {{ alert.generate(input) }} {% else %} {% if not input.hidden %} -
+ {% if formLayout == 'horizontal' %}
{% else %}
{% endif %} {% if formLayout == 'horizontal' %}
{% endif %} {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %}