Skip to content

Commit

Permalink
Version 3.0.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette authored Jan 25, 2019
2 parents 4d7bea9 + 2b99ea5 commit 7fa2ff1
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ php:
- 7
- 7.1
- 7.2
- 7.3

cache:
directories:
Expand Down Expand Up @@ -38,4 +39,4 @@ after_failure:

after_success:
- cd app/sprinkles/FormGenerator/
- bash <(curl -s https://codecov.io/bash)
- bash <(curl -s https://codecov.io/bash)
70 changes: 54 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)`.
Expand All @@ -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

<!--
## [Unreleased]
### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security
-->

[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
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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:
```
Expand Down Expand Up @@ -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 :
```
<button class="btn btn-success js-displayForm" data-toggle="modal" data-formUrl="/path/to/controller">Create</button>
<button class="btn btn-success js-displayForm" data-formUrl="/path/to/controller">Create</button>
```

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.
Expand All @@ -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"><i class="fa fa-trash-o"></i> Delete</a>
data-post-url="/project/delete"><i class="fa fa-trash-o"></i> Delete</a>
```
(Note that content of data attributes can be translation keys)

Expand All @@ -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
Expand Down Expand Up @@ -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:
```
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion asset-bundles.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 8 additions & 1 deletion assets/js/widget-formGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
DEBUG : false,
mainAlertElement : $('#alerts-page'),
redirectAfterSuccess : true,
autofocusModalElement : true
autofocusModalElement : true,
successCallback : function(data) {}
};

// Constructor
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {

Expand Down
30 changes: 0 additions & 30 deletions bower.json

This file was deleted.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"bootstrap-3-typeahead": "~4.0.2"
}
}
4 changes: 2 additions & 2 deletions templates/FormGenerator/FormGenerator.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{ alert.generate(input) }}
{% else %}
{% if not input.hidden %}
<div class="form-group has-feedback">
{% if formLayout == 'horizontal' %}<div class="form-group has-feedback clearfix">{% else %}<div class="form-group has-feedback">{% endif %}
{% if formLayout == 'horizontal' %}<label for="{{input.id}}" class="col-sm-2 control-label">{% else %}<label for="{{input.id}}">{% endif %}
{% if input.label %}{{translate(input.label)}}{% else %}&nbsp;{% endif %}
</label>
Expand All @@ -30,4 +30,4 @@
</div>
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}

0 comments on commit 7fa2ff1

Please sign in to comment.