Download the PHP package sheadawson/quickaddnew without Composer
On this page you can find all versions of the php package sheadawson/quickaddnew. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sheadawson/quickaddnew
More information about sheadawson/quickaddnew
Files in sheadawson/quickaddnew
Package quickaddnew
Short Description A decorator for form fields that manage object relationships, to allow adding a new object on the fly through a dialog window. It can handle has_one, has_many or many_many relationships. At the moment it has been tested / works on DropdownField and ListboxField. It works both in the CMS and in the frontend.
License BSD-3-Clause
Informations about the package quickaddnew
silverstripe-quickaddnew
What is it?
A decorator for form fields that manage object relationships, to allow adding a new object on the fly through a dialog window. It can handle has_one
,has_many
or many_many
relationships. At the moment it has been tested / works on DropdownField
(and SearchableDropdownField
), ListboxField
and CheckboxSetField
. It works both in the CMS and in the frontend.
Requirements
SilverStripe 4/5
For SilverStripe, check branch 1.1
Usage
Firstly, when creating the form field, we need to create a closure that returns the source array to populate the field's options. We do this because later on, when the field is refreshed with the newly created Object ID as it's value, we need to use this function Again to get up to date data for the source.
Then we can create the form field, calling the closure as the source argument
Next, we can tell the field to use and configure quickaddnew with useAddNew
.
- The first parameter is the class name of the object that will be created.
- The second is the $source closure
- (optional) The third allows you to pass a specific set of fields to display in the dialog
- (optional) The fourth allows you to pass a validator
- (optional) The fifth allows you to specify if this is a frontend field
These allow you to customise the fields and required fields (for validation) for the dialog.
By default the object class's getAddNewFields()
or getCMSFields()
methods are used
Add the field to your FieldList
All versions of quickaddnew with dependencies
silverstripe/recipe-plugin Version ^1 || ^2
silverstripe/vendor-plugin Version ^1 || ^2
silverstripe/framework Version ^4.4 || ^5