Skip to content

Commit f424761

Browse files
author
Eugene Tupikov
committed
ability to prepend new row instead of append
1 parent 4f4a0c3 commit f424761

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
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.21.0 (in development)
55
=======================
66

7+
- #279 ability to prepend new row instead of append
8+
79
2.20.6
810
======
911

src/MultipleInput.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ class MultipleInput extends InputWidget
210210
*/
211211
public $showGeneralError = false;
212212

213+
/**
214+
* @var bool add a new line to the beginning of the list, not to the end
215+
*/
216+
public $prepend = false;
217+
213218
/**
214219
* Initialization.
215220
*
@@ -350,15 +355,16 @@ protected function createRenderer()
350355
'extraButtons' => $this->extraButtons,
351356
'layoutConfig' => $this->layoutConfig,
352357
'iconMap' => $iconMap,
353-
'theme' => $this->theme
358+
'theme' => $this->theme,
359+
'prepend' => $this->prepend
354360
];
355361

356362
if ($this->showGeneralError) {
357363
$config['jsExtraSettings'] = [
358364
'showGeneralError' => true
359365
];
360366
}
361-
367+
362368
if ($this->removeButtonOptions !== null) {
363369
$config['removeButtonOptions'] = $this->removeButtonOptions;
364370
}

src/TabularInput.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ class TabularInput extends Widget
199199
*/
200200
public $iconSource = self::ICONS_SOURCE_GLYPHICONS;
201201

202+
/**
203+
* @var bool add a new line to the beginning of the list, not to the end
204+
*/
205+
public $prepend = false;
206+
202207
/**
203208
* Initialization.
204209
*
@@ -298,7 +303,8 @@ protected function createRenderer()
298303
'extraButtons' => $this->extraButtons,
299304
'layoutConfig' => $this->layoutConfig,
300305
'iconMap' => $iconMap,
301-
'theme' => $this->theme
306+
'theme' => $this->theme,
307+
'prepend' => $this->prepend
302308
];
303309

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

src/assets/src/js/jquery.multipleInput.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@
101101
*/
102102
indexPlaceholder: 'multiple_index',
103103

104-
showGeneralError: false
104+
showGeneralError: false,
105+
106+
prepend: false
105107
};
106108

107109
var isActiveFormEnabled = false;
@@ -264,7 +266,12 @@
264266
return;
265267
}
266268

267-
$addedInput.hide().appendTo(inputList).fadeIn(300);
269+
270+
if (settings.prepend) {
271+
$addedInput.hide().prependTo(inputList).fadeIn(300);
272+
} else {
273+
$addedInput.hide().appendTo(inputList).fadeIn(300);
274+
}
268275

269276
if (values instanceof Object) {
270277
var tmp = [];

src/assets/src/js/jquery.multipleInput.min.js

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

src/renderers/BaseRenderer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ abstract class BaseRenderer extends BaseObject implements RendererInterface
188188
*/
189189
public $jsPositions = [View::POS_HEAD, View::POS_BEGIN, View::POS_END, View::POS_READY, View::POS_LOAD];
190190

191+
/**
192+
* @var bool add a new line to the beginning of the list, not to the end
193+
*/
194+
public $prepend = false;
195+
191196
/**
192197
* @inheritdoc
193198
*/
@@ -411,7 +416,8 @@ public function render()
411416
'max' => $this->max,
412417
'min' => $this->min,
413418
'attributes' => $this->prepareJsAttributes(),
414-
'indexPlaceholder' => $this->getIndexPlaceholder()
419+
'indexPlaceholder' => $this->getIndexPlaceholder(),
420+
'prepend' => $this->prepend
415421
], $this->jsExtraSettings));
416422

417423
$js = "jQuery('#{$this->id}').multipleInput($options);";

0 commit comments

Comments
 (0)