3
3
[ ![ Version] ( http://img.shields.io/packagist/v/fullscreeninteractive/silverstripe-manyfield.svg )] ( https://packagist.org/packages/fullscreeninteractive/silverstripe-manyfield )
4
4
[ ![ License] ( http://img.shields.io/packagist/l/fullscreeninteractive/silverstripe-manyfield.svg )] ( license.md )
5
5
6
- A reusable approach to a form field which allows you to create and delete rows.
6
+ A reusable approach to a form field which allows you to create and delete rows
7
+ in Forms.
8
+
9
+ This is designed to work on the front-end with limited javascript (i.e it does
10
+ not require ` GridField ` or entwine).
7
11
8
12
Each row can relate to a DataObject subclass or simply to be used to capture the
9
- data
13
+ data as an array.
10
14
11
15
## Installation
12
16
@@ -31,4 +35,47 @@ $fields = new FieldList(
31
35
);
32
36
```
33
37
34
- Data will either be saved as ` setSwabList($data) ` , ` SwabList ` database field or in the ` SwabList ` relation.
38
+ Data will either be saved as ` setSwabList($data) ` , ` SwabList ` database field or
39
+ in the ` SwabList ` relation. If you are saving into a relation such as ` HasMany `
40
+ or ` ManyMany ` list then make sure you include a hidden field in your field list.
41
+
42
+ ```
43
+ $many = ManyField::create('SwabList', [
44
+ HiddenField::create('ID', ''),
45
+ TextField::create('Swab'),
46
+ TextField::create('TestSite'),
47
+ TextField::create('Description'),
48
+ TextField::create('Material')
49
+ ]);
50
+ ```
51
+
52
+ ## Sorting
53
+
54
+ Include a Hidden field ` Sort ` and make sure sorting is enabled.
55
+
56
+ ```
57
+ $many = ManyField::create('SwabList', [
58
+ HiddenField::create('ID', ''),
59
+ HiddenField::create('Sort', ''),
60
+ TextField::create('TestSite')
61
+ ])->setCanSort(true);
62
+ ```
63
+
64
+ ## Required Fields
65
+
66
+ $many = ManyField::create('SwabList', [
67
+ TextField::create('TestSite')->setRequired(true)
68
+ ])->setCanSort(true);
69
+
70
+ ## Javascript Events
71
+
72
+ If you have UI handlers that need to run when fields are added or removed
73
+ (such as Date Pickers) create a handler on your ` <body> ` element and listen for
74
+ either:
75
+
76
+ * ` manyFieldAdded `
77
+ * ` manyFieldRemoved `
78
+
79
+ ## Licence
80
+
81
+ BSD 3-Clause License
0 commit comments