Skip to content

Commit 5a3300e

Browse files
Sorting + FIX (hasProperty to hasAttribute)
1 parent 5256627 commit 5a3300e

10 files changed

+793
-4
lines changed

src/MultipleInput.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class MultipleInput extends InputWidget
123123
*/
124124
public $form;
125125

126+
/**
127+
* @var bool allow sorting.
128+
* @internal this property is used when need to allow sorting rows.
129+
*/
130+
public $sortable = false;
131+
126132
/**
127133
* Initialization.
128134
*
@@ -155,7 +161,7 @@ protected function initData()
155161
}
156162

157163
if ($this->model instanceof Model) {
158-
$data = $this->model->hasProperty($this->attribute)
164+
$data = $this->model->hasAttribute($this->attribute)
159165
? ArrayHelper::getValue($this->model, $this->attribute, [])
160166
: [];
161167

@@ -219,7 +225,8 @@ private function createRenderer()
219225
'addButtonPosition' => $this->addButtonPosition,
220226
'rowOptions' => $this->rowOptions,
221227
'context' => $this,
222-
'form' => $this->form
228+
'form' => $this->form,
229+
'sortable' => $this->sortable
223230
];
224231

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

src/TabularInput.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class TabularInput extends Widget
109109
*/
110110
public $form;
111111

112+
/**
113+
* @var bool allow sorting.
114+
* @internal this property is used when need to allow sorting rows.
115+
*/
116+
public $sortable = false;
117+
112118
/**
113119
* Initialization.
114120
*
@@ -158,7 +164,8 @@ private function createRenderer()
158164
'rowOptions' => $this->rowOptions,
159165
'addButtonPosition' => $this->addButtonPosition,
160166
'context' => $this,
161-
'form' => $this->form
167+
'form' => $this->form,
168+
'sortable' => $this->sortable
162169
];
163170

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

src/assets/MultipleInputAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class MultipleInputAsset extends AssetBundle
1818
{
1919
public $css = [
20-
'css/multiple-input.css'
20+
YII_DEBUG ? 'css/multiple-input.css' : 'css/multiple-input.min.css'
2121
];
2222

2323
public $js = [];
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* @link https://github.com/unclead/yii2-multiple-input
5+
* @copyright Copyright (c) 2014 unclead
6+
* @license https://github.com/unclead/yii2-multiple-input/blob/master/LICENSE.md
7+
*/
8+
9+
namespace unclead\multipleinput\assets;
10+
11+
use yii\web\AssetBundle;
12+
13+
/**
14+
* Class MultipleInputAsset
15+
* @package unclead\multipleinput\assets
16+
*/
17+
class MultipleInputSortableAsset extends AssetBundle
18+
{
19+
public $sourcePath = __DIR__ . '/src/';
20+
21+
public $css = [
22+
YII_DEBUG ? 'css/sorting.css' : 'css/sorting.min.css'
23+
];
24+
25+
public $js = [
26+
YII_DEBUG ? 'js/jquery-sortable.js' : 'js/jquery-sortable.min.js'
27+
];
28+
29+
public $depends = [
30+
'unclead\multipleinput\assets\MultipleInputAsset',
31+
];
32+
33+
}

src/assets/src/css/multiple-input.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/src/css/sorting.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.multiple-input-list__item,
2+
.dragging,
3+
.dragging * {
4+
cursor: move !important;
5+
}
6+
7+
.dragged {
8+
position: absolute
9+
top: 0
10+
opacity: .5
11+
z-index: 2000
12+
}
13+
14+
tr.placeholder {
15+
display: block;
16+
background: red;
17+
position: relative;
18+
margin: 0;
19+
padding: 0;
20+
border: none;
21+
}
22+
23+
tr.placeholder:before {
24+
content: "";
25+
position: absolute;
26+
width: 0;
27+
height: 0;
28+
border: 5px solid transparent;
29+
border-left-color: red;
30+
margin-top: -5px;
31+
left: -5px;
32+
border-right: none;
33+
}

src/assets/src/css/sorting.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)