Skip to content

Commit f96092c

Browse files
author
Eugene Tupikov
committed
Fixed displaying add button in case there is no definition of columns + update README
1 parent dd0d61d commit f96092c

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Yii2 multiple input change log
44
1.2.3 in development
55
--------------------
66

7+
- Enh #34: Added options `allowEmptyList` (unclead)
8+
79
1.2.2
810
-----
911

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Contents:
1515
- [Installation](#installation)
1616
- [Configuration](#configuration)
1717
- [Usage](#usage)
18-
- [How to customize buttons](#customize-buttons)
18+
- [Tips and tricks](#tips)
1919
- [Javascript Events](#javascript-events)
2020
- [Renderers](#renderers)
2121

@@ -241,7 +241,11 @@ You can find more detail about this use case [here](docs/tabular_input.md)
241241

242242
> Also you can find source code of examples [here](./docs/examples/)
243243
244-
## How to customize buttons
244+
245+
246+
## Tips and tricks
247+
248+
### How to customize buttons
245249

246250
You can customize `add` and `remove` buttons via `addButtonOptions` and `removeButtonOptions`. Here is the simple example
247251
how you can use those options:
@@ -262,6 +266,20 @@ how you can use those options:
262266

263267
```
264268

269+
### Work with empty list
270+
271+
In some cases you need to have the ability to delete all rows in the list. For this purpose you can use option `allowEmptyList` like in the example below:
272+
273+
```php
274+
275+
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
276+
'limit' => 5,
277+
'allowEmptyList' => true
278+
])
279+
->label(false);
280+
281+
```
282+
265283
## JavaScript events
266284
This widget has following events:
267285
- `afterInit`: triggered after initialization

examples/views/multiple-input.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
<h3>Single column</h3>
2525
<?php
2626
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
27-
'limit' => 5
27+
'limit' => 5,
28+
'allowEmptyList' => true
2829
])
2930
->label(false);
3031
?>

src/renderers/TableRenderer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function renderHeader()
7272
*/
7373
private function hasHeader()
7474
{
75+
if ($this->allowEmptyList) {
76+
return true;
77+
}
7578
foreach ($this->columns as $column) {
7679
/* @var $column BaseColumn */
7780
if (!empty($column->title)) {

0 commit comments

Comments
 (0)