Skip to content

Commit 7fea726

Browse files
authored
Merge pull request #628 from wkhaliddev1/docs-repeatelementswkhaliddev1
[Docs] repeat-elements: Added phpdocs for delete with an example
2 parents c03d745 + 4979851 commit 7fea726

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/apis/subsystems/form/advanced/repeat-elements.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Most of the necessary information is in the phpdoc comment for the repeat_elemen
3636
* @param int $addfieldsno how many fields to add at a time
3737
* @param string $addstring name of button, {no} is replaced by no of blanks that will be added.
3838
* @param bool $addbuttoninside if true, don't call closeHeaderBefore($addfieldsname). Default false.
39+
* @param string $deletebuttonname if specified, treats the no-submit button with this name as a "delete element" button in each of the elements.
3940
* @return int no of repeats of element in this page
4041
*/
4142
```
@@ -56,13 +57,14 @@ While the elements are zero-indexed, the `{no}` label is one-indexed.
5657
- The label used for the 'Add more' button can be set using the `$addstring` parameter. A `{no}` placeholder can be used in the string to indicate how many repeats will be added.
5758
- The number of element repeats currently shown is stored in a hidden element, whose name can be specified using the `$repeathiddenname` parameter.
5859

59-
The following example shows how `repeat_elements()` can be used within a form definition:
60+
The following example shows how `repeat_elements()` can be used within a form definition with a delete button for each repeated field :
6061

6162
```php title="definition() function"
6263
$repeatarray = [
6364
$mform->createElement('text', 'option', get_string('optionno', 'choice')),
6465
$mform->createElement('text', 'limit', get_string('limitno', 'choice')),
6566
$mform->createElement('hidden', 'optionid', 0),
67+
$mform->createElement('submit', 'delete', get_string('deletestr', 'choice'), [], false),
6668
];
6769

6870

@@ -99,7 +101,8 @@ $this->repeat_elements(
99101
'option_add_fields',
100102
3,
101103
null,
102-
true
104+
true,
105+
'delete',
103106
);
104107
```
105108

0 commit comments

Comments
 (0)