Skip to content

Commit a3a2cc0

Browse files
committed
Using of an id instead of uniqueHash
1 parent 14dd721 commit a3a2cc0

File tree

4 files changed

+11
-33
lines changed

4 files changed

+11
-33
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
min: 1,
6060
attributeOptions: {},
6161
indexPlaceholder: 'multiple_index',
62-
uniqueHash: null
6362
};
6463

6564
var defaultAttributeOptions = {
@@ -176,10 +175,9 @@
176175
data = $wrapper.data('multipleInput'),
177176
settings = data.settings,
178177
template = settings.template,
179-
inputList = $wrapper.find('.multiple-input-list.' + settings.uniqueHash).first(),
180-
count = $wrapper.find('.multiple-input-list__item.' + settings.uniqueHash).length;
178+
inputList = $wrapper.children('.multiple-input-list').first();
181179

182-
if (settings.limit != null && count >= settings.limit) {
180+
if (settings.limit != null && getCurrentIndex($wrapper) >= settings.limit) {
183181
return;
184182
}
185183

@@ -250,10 +248,9 @@
250248
var $wrapper = $btn.closest('.multiple-input').first(),
251249
$toDelete = $btn.closest('.multiple-input-list__item'),
252250
data = $wrapper.data('multipleInput'),
253-
settings = data.settings,
254-
count = $('.multiple-input-list__item.' + settings.uniqueHash).length;
251+
settings = data.settings;
255252

256-
if (count > settings.min) {
253+
if (getCurrentIndex($wrapper) > settings.min) {
257254
var event = $.Event(events.beforeDeleteRow);
258255
$wrapper.trigger(event, [$toDelete]);
259256

@@ -345,12 +342,10 @@
345342
};
346343

347344
var getCurrentIndex = function($wrapper) {
348-
if (typeof $wrapper.data('multipleInput') !== 'object') {
349-
return 0;
350-
}
351-
352345
return $wrapper
353-
.find('.multiple-input-list__item.' + $wrapper.data('multipleInput').settings.uniqueHash)
346+
.children('.multiple-input-list')
347+
.children('tbody')
348+
.children('.multiple-input-list__item')
354349
.length;
355350
};
356351

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/components/BaseRenderer.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ abstract class BaseRenderer extends Object
114114
* @var string
115115
*/
116116
private $indexPlaceholder;
117-
118-
/**
119-
* @var string
120-
*/
121-
private $uniqueHash;
122117

123118
/**
124119
* @param $context
@@ -265,8 +260,7 @@ protected function registerAssets()
265260
'limit' => $this->limit,
266261
'min' => $this->min,
267262
'attributeOptions' => $this->attributeOptions,
268-
'indexPlaceholder' => $this->getIndexPlaceholder(),
269-
'uniqueHash' => $this->getUniqueHash()
263+
'indexPlaceholder' => $this->getIndexPlaceholder()
270264
]);
271265

272266
$js = "jQuery('#{$this->id}').multipleInput($options);";
@@ -305,14 +299,6 @@ public function getIndexPlaceholder()
305299
return $this->indexPlaceholder;
306300
}
307301

308-
/**
309-
* @return string
310-
*/
311-
public function getUniqueHash()
312-
{
313-
return $this->uniqueHash;
314-
}
315-
316302
/**
317303
* @return bool
318304
*/
@@ -339,7 +325,6 @@ protected function isAddButtonPositionRow()
339325

340326
private function prepareIndexPlaceholder()
341327
{
342-
$this->uniqueHash = uniqid();
343-
$this->indexPlaceholder = 'multiple-index-' . $this->uniqueHash;
328+
$this->indexPlaceholder = 'multiple_index_' . $this->id;
344329
}
345330
}

src/renderers/TableRenderer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ protected function internalRender()
3737

3838
$options = [];
3939
Html::addCssClass($options, 'multiple-input-list table table-condensed');
40-
Html::addCssClass($options, $this->getUniqueHash());
4140

4241
$content = Html::tag('table', implode("\n", $content), $options);
4342

@@ -213,13 +212,12 @@ private function renderRowContent($index = null, $item = null)
213212
protected function prepareRowOptions($index, $item)
214213
{
215214
if (is_callable($this->rowOptions)) {
216-
$options =call_user_func($this->rowOptions, $item, $index, $this->context);
215+
$options = call_user_func($this->rowOptions, $item, $index, $this->context);
217216
} else {
218217
$options = $this->rowOptions;
219218
}
220219

221220
Html::addCssClass($options, 'multiple-input-list__item');
222-
Html::addCssClass($options, $this->getUniqueHash());
223221

224222
return $options;
225223
}

0 commit comments

Comments
 (0)