Skip to content

Commit 46bb2af

Browse files
author
Eugene Tupikov
committed
introduce the option theme to disable all bootstrap css classes + explicitly set tabindex for all inputs
1 parent 2c4ca72 commit 46bb2af

12 files changed

+268
-121
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
2.17.0 (in development)
55
=======================
66
- #215 collect all js script that has to be evaluate when add new row (not only from " on ready" section)
7+
- #198 introduce the option `theme` to disable all bootstrap css classes
8+
- #197 explicitly set tabindex for all inputs
79

810
2.16.0
911
======

examples/views/multiple-input.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
2727
'max' => 6,
2828
'allowEmptyList' => false,
29+
'sortable' => true,
2930
'columns' => [
3031
[
3132
'name' => 'emails',
@@ -60,6 +61,7 @@
6061
return $options;
6162
},
6263
'cloneButton' => true,
64+
6365
'columns' => [
6466
[
6567
'name' => 'user_id',
@@ -108,7 +110,7 @@
108110
'headerOptions' => [
109111
'style' => 'width: 250px;',
110112
'class' => 'day-css-class'
111-
]
113+
],
112114
],
113115
[
114116
'name' => 'priority',

examples/views/tabular-input.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use unclead\multipleinput\renderers\ListRenderer;
43
use yii\bootstrap\ActiveForm;
54
use unclead\multipleinput\TabularInput;
65
use yii\helpers\Html;
@@ -22,8 +21,8 @@
2221
<?= TabularInput::widget([
2322
'models' => $models,
2423
'modelClass' => Item::class,
25-
'rendererClass' => ListRenderer::class,
2624
'cloneButton' => true,
25+
'sortable' => true,
2726
'min' => 0,
2827
'addButtonPosition' => [
2928
TabularInput::POS_HEADER,
@@ -64,25 +63,21 @@
6463
'name' => 'description',
6564
'title' => 'Description',
6665
],
67-
// [
68-
// 'name' => 'file',
69-
// 'title' => 'File',
70-
// 'type' => \vova07\fileapi\Widget::className(),
71-
// 'options' => [
72-
// 'settings' => [
73-
// 'url' => ['site/fileapi-upload']
74-
// ]
75-
// ]
76-
// ],
7766
[
7867
'name' => 'date',
79-
'type' => \kartik\date\DatePicker::className(),
68+
'type' => \kartik\date\DatePicker::class,
8069
'title' => 'Day',
8170
'options' => [
71+
'type' => \kartik\datecontrol\DateControl::FORMAT_DATE,
8272
'pluginOptions' => [
83-
'format' => 'dd.mm.yyyy',
84-
'todayHighlight' => true
85-
]
73+
'autoclose' => true,
74+
'format' => 'dd/mm/yyyy',
75+
'todayHighlight' => true,
76+
],
77+
'widgetOptions' => [
78+
'type' => \kartik\date\DatePicker::TYPE_INPUT,
79+
],
80+
8681
],
8782
'headerOptions' => [
8883
'style' => 'width: 250px;',

src/MultipleInput.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class MultipleInput extends InputWidget
3232
const POS_ROW_BEGIN = RendererInterface::POS_ROW_BEGIN;
3333
const POS_FOOTER = RendererInterface::POS_FOOTER;
3434

35+
const THEME_DEFAULT = 'default';
36+
const THEME_BS = 'bootstrap';
37+
38+
const ICONS_SOURCE_GLYPHICONS = 'glyphicons';
39+
const ICONS_SOURCE_FONTAWESOME = 'fa';
40+
3541
/**
3642
* @var ActiveRecordInterface[]|array[] input data
3743
*/
@@ -174,24 +180,30 @@ class MultipleInput extends InputWidget
174180
* --icon library classes mapped for various controls
175181
*/
176182
public $iconMap = [
177-
'glyphicons' => [
178-
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
179-
'remove' => 'glyphicon glyphicon-remove',
180-
'add' => 'glyphicon glyphicon-plus',
181-
'clone' => 'glyphicon glyphicon-duplicate',
183+
self::ICONS_SOURCE_GLYPHICONS => [
184+
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
185+
'remove' => 'glyphicon glyphicon-remove',
186+
'add' => 'glyphicon glyphicon-plus',
187+
'clone' => 'glyphicon glyphicon-duplicate',
182188
],
183-
'fa' => [
184-
'drag-handle' => 'fa fa-bars',
185-
'remove' => 'fa fa-times',
186-
'add' => 'fa fa-plus',
187-
'clone' => 'fa fa-files-o',
189+
self::ICONS_SOURCE_FONTAWESOME => [
190+
'drag-handle' => 'fa fa-bars',
191+
'remove' => 'fa fa-times',
192+
'add' => 'fa fa-plus',
193+
'clone' => 'fa fa-files-o',
188194
],
189195
];
190196
/**
191-
* @var string
192-
* --name of default icon library
197+
* @var string the name of default icon library
198+
*/
199+
public $iconSource = self::ICONS_SOURCE_GLYPHICONS;
200+
201+
/**
202+
* @var string the CSS theme of the widget
203+
*
204+
* @todo Use bootstrap theme for BC. We can switch to default theme in major release
193205
*/
194-
public $iconSource = 'glyphicons';
206+
public $theme = self::THEME_BS;
195207

196208
/**
197209
* Initialization.
@@ -289,12 +301,21 @@ private function createRenderer()
289301
array_unshift($this->columns, $drag);
290302
}
291303

304+
$available_themes = [
305+
self::THEME_BS,
306+
self::THEME_DEFAULT
307+
];
308+
309+
if (!in_array($this->theme, $available_themes, true)) {
310+
$this->theme = self::THEME_BS;
311+
}
312+
292313
/**
293314
* set default icon map
294315
*/
295316
$iconMap = array_key_exists($this->iconSource, $this->iconMap)
296317
? $this->iconMap[$this->iconSource]
297-
: $this->iconMap['glyphicons'];
318+
: $this->iconMap[self::ICONS_SOURCE_GLYPHICONS];
298319

299320
$config = [
300321
'id' => $this->getId(),
@@ -315,6 +336,7 @@ private function createRenderer()
315336
'extraButtons' => $this->extraButtons,
316337
'layoutConfig' => $this->layoutConfig,
317338
'iconMap' => $iconMap,
339+
'theme' => $this->theme
318340
];
319341

320342
if ($this->removeButtonOptions !== null) {

src/MultipleInputColumn.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
/**
1919
* Class MultipleInputColumn
2020
* @package unclead\multipleinput
21+
*
22+
* @property MultipleInput $context
2123
*/
2224
class MultipleInputColumn extends BaseColumn
2325
{
24-
/**
25-
* @var MultipleInput
26-
*/
27-
public $context;
28-
2926
/**
3027
* @throws InvalidConfigException
3128
*/

src/TabularColumn.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
/**
1515
* Class TabularColumn
1616
* @package unclead\multipleinput
17+
*
18+
* @property TabularInput $context
1719
*/
1820
class TabularColumn extends BaseColumn
1921
{
20-
/**
21-
* @var TabularInput
22-
*/
23-
public $context;
24-
2522
/**
2623
* Returns element's name.
2724
*

src/TabularInput.php

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class TabularInput extends Widget
2828
const POS_FOOTER = RendererInterface::POS_FOOTER;
2929
const POS_ROW_BEGIN = RendererInterface::POS_ROW_BEGIN;
3030

31+
const THEME_DEFAULT = 'default';
32+
const THEME_BS = 'bootstrap';
33+
34+
const ICONS_SOURCE_GLYPHICONS = 'glyphicons';
35+
const ICONS_SOURCE_FONTAWESOME = 'fa';
36+
3137
/**
3238
* @var array
3339
*/
@@ -167,24 +173,31 @@ class TabularInput extends Widget
167173
* --icon library classes mapped for various controls
168174
*/
169175
public $iconMap = [
170-
'glyphicons' => [
171-
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
172-
'remove' => 'glyphicon glyphicon-remove',
173-
'add' => 'glyphicon glyphicon-plus',
174-
'clone' => 'glyphicon glyphicon-duplicate',
176+
self::ICONS_SOURCE_GLYPHICONS => [
177+
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
178+
'remove' => 'glyphicon glyphicon-remove',
179+
'add' => 'glyphicon glyphicon-plus',
180+
'clone' => 'glyphicon glyphicon-duplicate',
175181
],
176-
'fa' => [
177-
'drag-handle' => 'fa fa-bars',
178-
'remove' => 'fa fa-times',
179-
'add' => 'fa fa-plus',
180-
'clone' => 'fa fa-files-o',
182+
self::ICONS_SOURCE_FONTAWESOME => [
183+
'drag-handle' => 'fa fa-bars',
184+
'remove' => 'fa fa-times',
185+
'add' => 'fa fa-plus',
186+
'clone' => 'fa fa-files-o',
181187
],
182188
];
189+
190+
/**
191+
* @var string the CSS theme of the widget
192+
*
193+
* @todo Use bootstrap theme for BC. We can switch to default theme in major release
194+
*/
195+
public $theme = self::THEME_BS;
196+
183197
/**
184-
* @var string
185-
* --name of default icon library
198+
* @var string the name of default icon library
186199
*/
187-
public $iconSource = 'glyphicons';
200+
public $iconSource = self::ICONS_SOURCE_GLYPHICONS;
188201

189202
/**
190203
* Initialization.
@@ -238,12 +251,33 @@ public function run()
238251
*/
239252
private function createRenderer()
240253
{
254+
if($this->sortable) {
255+
$drag = [
256+
'name' => 'drag',
257+
'type' => TabularColumn::TYPE_DRAGCOLUMN,
258+
'headerOptions' => [
259+
'style' => 'width: 20px;',
260+
]
261+
];
262+
263+
array_unshift($this->columns, $drag);
264+
}
265+
266+
$available_themes = [
267+
self::THEME_BS,
268+
self::THEME_DEFAULT
269+
];
270+
271+
if (!in_array($this->theme, $available_themes, true)) {
272+
$this->theme = self::THEME_BS;
273+
}
274+
241275
/**
242276
* set default icon map
243277
*/
244278
$iconMap = array_key_exists($this->iconSource, $this->iconMap)
245279
? $this->iconMap[$this->iconSource]
246-
: $this->iconMap['glyphicons'];
280+
: $this->iconMap[self::ICONS_SOURCE_GLYPHICONS];
247281

248282
$config = [
249283
'id' => $this->getId(),
@@ -264,6 +298,7 @@ private function createRenderer()
264298
'extraButtons' => $this->extraButtons,
265299
'layoutConfig' => $this->layoutConfig,
266300
'iconMap' => $iconMap,
301+
'theme' => $this->theme
267302
];
268303

269304
if ($this->removeButtonOptions !== null) {

0 commit comments

Comments
 (0)