|
16 | 16 | btn_action: null,
|
17 | 17 | btn_type: null,
|
18 | 18 | limit: 1,
|
19 |
| - replacement: [] |
| 19 | + replacement: [], |
| 20 | + currentIndex: 0 |
20 | 21 | };
|
21 | 22 |
|
22 | 23 | var attributeDefaults = {};
|
23 | 24 |
|
| 25 | + var currentIndex = 0; |
| 26 | + |
| 27 | + |
24 | 28 | var methods = {
|
25 | 29 | init: function (options) {
|
26 | 30 | var settings = $.extend(defaultOptions, options || {});
|
|
41 | 45 | setTimeout(function() {
|
42 | 46 | var attributes = form.data('yiiActiveForm').attributes;
|
43 | 47 | $.each(attributes[0], function(key, value) {
|
44 |
| - attributeDefaults[key] = value; |
| 48 | + if (['id', 'input', 'container'].indexOf(key) == -1) { |
| 49 | + attributeDefaults[key] = value; |
| 50 | + } |
45 | 51 | });
|
46 | 52 | form.data('yiiActiveForm').attributes = [];
|
47 | 53 |
|
48 | 54 | wrapper.find('.multiple-input-list').find('input, select, textarea').each(function () {
|
49 | 55 | methods.addAttribute.apply(this);
|
50 | 56 | });
|
| 57 | + |
| 58 | + currentIndex = $('#' + settings.id).find('.multiple-input-list__item').length; |
51 | 59 | }, 100);
|
52 | 60 | },
|
53 | 61 |
|
54 | 62 | addInput: function (settings) {
|
55 | 63 | var template = settings.template,
|
56 |
| - $wrapper = $(this).parents('.multiple-input-list').first(), |
57 |
| - index = $wrapper.find('.multiple-input-list__item').length, |
58 |
| - btn_action = settings.btn_action, |
59 |
| - btn_type = settings.btn_type, |
| 64 | + parent = $('#' + settings.id), |
| 65 | + inputList = parent.find('.multiple-input-list').first(), |
| 66 | + count = parent.find('.multiple-input-list__item').length, |
60 | 67 | replacement = settings.replacement || [];
|
61 | 68 |
|
62 |
| - if (settings.limit != null && index >= settings.limit) { |
| 69 | + if (settings.limit != null && count >= settings.limit) { |
63 | 70 | return;
|
64 | 71 | }
|
65 | 72 | var search = ['{index}', '{btn_action}', '{btn_type}', '{value}'],
|
66 |
| - replace = [index, btn_action, btn_type, '']; |
| 73 | + replace = [currentIndex, settings.btn_action, settings.btn_type, '']; |
67 | 74 |
|
68 | 75 | for (var i in search) {
|
69 | 76 | template = template.replaceAll(search[i], replace[i]);
|
|
73 | 80 | template = template.replaceAll('{' + j + '}', replacement[j]);
|
74 | 81 | }
|
75 | 82 |
|
76 |
| - |
77 |
| - $(template).hide().appendTo($wrapper).fadeIn(300); |
| 83 | + $(template).hide().appendTo(inputList).fadeIn(300); |
78 | 84 | $(template).find('input, select, textarea').each(function () {
|
79 | 85 | methods.addAttribute.apply(this);
|
80 | 86 | });
|
| 87 | + |
| 88 | + currentIndex++; |
81 | 89 | },
|
82 | 90 |
|
83 | 91 | removeInput: function () {
|
|
0 commit comments