Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/becklyn/orderedformbundle
This bundle adds functionality for ordering form elements
https://github.com/becklyn/orderedformbundle
forms php symfony symfony-bundle
Last synced: 2 days ago
JSON representation
This bundle adds functionality for ordering form elements
- Host: GitHub
- URL: https://github.com/becklyn/orderedformbundle
- Owner: Becklyn
- License: bsd-3-clause
- Created: 2018-02-15T17:20:08.000Z (over 6 years ago)
- Default Branch: 1.x
- Last Pushed: 2024-01-17T12:54:07.000Z (10 months ago)
- Last Synced: 2024-04-15T00:45:30.210Z (7 months ago)
- Topics: forms, php, symfony, symfony-bundle
- Language: PHP
- Size: 58.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Ordered Form Bundle
===================A bundle that makes form fields sortable.
Installation
------------```bash
composer require becklyn/ordered-form-bundle
```Usage
-----This bundle adds a new form option called `position`:
```php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;class SomeForm extends AbstractType
{
/**
* @inheritDoc
*/
public function buildForm (FormBuilderInterface $builder, array $options) : void
{
$builder
->add("field", null, [
"position" => /* some value */
]);
}
}
```The supported values are:
| Value | Description |
| ----- | ----------- |
| `"position" => "first"` | Places the element as the first element in the form. |
| `"position" => "last"` | Places the element as the last element in the form. |
| `"position" => 42` | A simple sort order (the lower the number, the more at the top it is). Works with any integer. |
| `"position" => ["before" => "otherfield"]` | Places the field before another one. |
| `"position" => ["after" => "otherfield"]` | Places the field after another one. |Caveats
-------This bundle focuses on speed, so the sorting is not perfect. As it is pretty easy to create a conflicting, this bundle
tries a best-effort sorting, but this implies:* A `first` field isn't guaranteed to be the first one (eg. if there are multiple `first`).
* `before` and `after` only guarantee the relative order, not how big the distance is between these fields (it tries
to place them immediately next to each other).
If the configuration of the form is sensible and conflict-free, then the order will work as expected.