Skip to content

Commit 07c2a70

Browse files
committed
Revert #37
1 parent d08fe29 commit 07c2a70

File tree

9 files changed

+43
-148
lines changed

9 files changed

+43
-148
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Yii2 multiple input change log
55
---------------------
66

77
- Bug #70: replacing of the placeholder after preparing the content of row
8-
- Enh #37: Added support of client validation
98

109
1.2.15
1110
------

README.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Contents:
2121
- [Guess column title](#guess-column-title)
2222
- [Ajax loading of a widget](#ajax-loading)
2323
- [Use of a widget's placeholder](#using-placeholder)
24-
- [How to enable client validation](#client-validation)
2524
- [Javascript Events](#javascript-events)
2625
- [Renderers](#renderers)
2726

@@ -120,10 +119,6 @@ function($data) {}
120119

121120
**errorOptions** *array*: the HTMl attributes for the error tag
122121

123-
**attributeOptions** *array*: client-side attribute options of the column.
124-
You can use it to configure a column in specific way, e.g. you can enable client validation for particular
125-
column meanwhile other columns will be validated via ajax validation
126-
127122

128123
### Input types
129124

@@ -422,50 +417,6 @@ JS
422417
?>
423418
```
424419

425-
### How to enable client validation <a id="client-validation"></a>
426-
427-
Apart of ajax validation you can use client validation but in this case you MUST set property `form`.
428-
Also ensure that you set `enableClientValidation` to `true` value in property `attributeOptions`. If you want to use client validation
429-
for particular column you can use `attributeOptions` property for this column. An example of using client validation is listed below:
430-
431-
```php
432-
<?= TabularInput::widget([
433-
'models' => $models,
434-
'form' => $form,
435-
'attributeOptions' => [
436-
'enableAjaxValidation' => true,
437-
'enableClientValidation' => false,
438-
'validateOnChange' => false,
439-
'validateOnSubmit' => true,
440-
'validateOnBlur' => false,
441-
],
442-
'columns' => [
443-
[
444-
'name' => 'id',
445-
'type' => TabularColumn::TYPE_HIDDEN_INPUT
446-
],
447-
[
448-
'name' => 'title',
449-
'title' => 'Title',
450-
'type' => TabularColumn::TYPE_TEXT_INPUT,
451-
'attributeOptions' => [
452-
'enableClientValidation' => true,
453-
'validateOnChange' => true,
454-
],
455-
'enableError' => true
456-
],
457-
[
458-
'name' => 'description',
459-
'title' => 'Description',
460-
],
461-
],
462-
]) ?>
463-
464-
```
465-
466-
In the example above we use client validation for column `title` and ajax validation for column `description`.
467-
As you can noticed we also enabled `validateOnChange` for column `title` thus you can use all client-side options from the `ActiveField` class.
468-
469420

470421
## JavaScript events
471422
This widget has following events:

examples/views/tabular-input.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
'name' => 'title',
3838
'title' => 'Title',
3939
'type' => TabularColumn::TYPE_TEXT_INPUT,
40-
'attributeOptions' => [
41-
'enableClientValidation' => true,
42-
'validateOnChange' => true,
43-
],
4440
'enableError' => true
4541
],
4642
[

src/MultipleInput.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Yii;
1212
use yii\base\Model;
13-
use yii\widgets\ActiveForm;
1413
use yii\widgets\InputWidget;
1514
use yii\db\ActiveRecordInterface;
1615
use unclead\widgets\renderers\TableRenderer;
@@ -100,11 +99,6 @@ class MultipleInput extends InputWidget
10099
*/
101100
public $columnClass;
102101

103-
/**
104-
* @var ActiveForm the instance of `ActiveForm` class.
105-
*/
106-
public $form;
107-
108102
/**
109103
* Initialization.
110104
*
@@ -173,7 +167,6 @@ private function createRenderer()
173167
'addButtonPosition' => $this->addButtonPosition,
174168
'rowOptions' => $this->rowOptions,
175169
'context' => $this,
176-
'form' => $this->form
177170
];
178171

179172
if (!is_null($this->removeButtonOptions)) {

src/TabularInput.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use yii\db\ActiveRecordInterface;
1515
use yii\bootstrap\Widget;
1616
use unclead\widgets\renderers\TableRenderer;
17-
use yii\widgets\ActiveForm;
1817

1918
/**
2019
* Class TabularInput
@@ -95,11 +94,6 @@ class TabularInput extends Widget
9594
*/
9695
public $columnClass;
9796

98-
/**
99-
* @var ActiveForm the instance of `ActiveForm` class.
100-
*/
101-
public $form;
102-
10397
/**
10498
* Initialization.
10599
*
@@ -145,7 +139,6 @@ private function createRenderer()
145139
'rowOptions' => $this->rowOptions,
146140
'addButtonPosition' => $this->addButtonPosition,
147141
'context' => $this,
148-
'form' => $this->form
149142
];
150143

151144
if (!is_null($this->removeButtonOptions)) {

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

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,27 @@
5656
// how many row has to renders
5757
limit: 1,
5858
// minimum number of rows
59-
min: 1,
59+
min: 1
60+
};
6061

61-
attributes: {}
62+
var defaultAttributeOptions = {
63+
enableAjaxValidation: false,
64+
validateOnBlur: false,
65+
validateOnChange: false,
66+
validateOnType: false
6267
};
6368

6469
var methods = {
6570
init: function (options) {
6671
var settings = $.extend(true, {}, defaultOptions, options || {}),
6772
$wrapper = $('#' + settings.id),
68-
form = $wrapper.closest('form');
69-
73+
form = $wrapper.closest('form'),
74+
id = this.selector.replace('#', '');
75+
7076
$wrapper.data('multipleInput', {
7177
settings: settings,
7278
currentIndex: 0,
73-
attributes: {}
79+
attributeDefaults: {}
7480
});
7581

7682

@@ -86,7 +92,25 @@
8692

8793
var intervalID = setInterval(function () {
8894
if (typeof form.data('yiiActiveForm') === 'object') {
89-
$wrapper.data('multipleInput').attributes = settings.attributes;
95+
var attribute = form.yiiActiveForm('find', id);
96+
var attributeDefaults = [];
97+
if (typeof attribute === 'object') {
98+
$.each(attribute, function (key, value) {
99+
if (['id', 'input', 'container'].indexOf(key) == -1) {
100+
attributeDefaults[key] = value;
101+
}
102+
});
103+
form.yiiActiveForm('remove', id);
104+
}
105+
106+
var attributeOptions = $.extend({}, defaultAttributeOptions, settings.attributeOptions);
107+
$.each(attributeOptions, function (key, value) {
108+
if (typeof attributeDefaults[key] === 'undefined') {
109+
attributeDefaults[key] = value;
110+
}
111+
});
112+
113+
$wrapper.data('multipleInput').attributeDefaults = attributeDefaults;
90114

91115
$wrapper.find('.multiple-input-list').find('input, select, textarea').each(function () {
92116
addAttribute($(this));
@@ -99,11 +123,9 @@
99123
}
100124
}, 100);
101125
},
102-
103126
add: function (values) {
104127
addInput($(this), values);
105128
},
106-
107129
remove: function (index) {
108130
var row = null;
109131
if (index) {
@@ -113,7 +135,6 @@
113135
}
114136
removeInput(row);
115137
},
116-
117138
clear: function () {
118139
$('.js-input-remove').each(function () {
119140
removeInput($(this));
@@ -148,17 +169,18 @@
148169
}
149170

150171
var index = 0;
151-
152172
$(template).find('input, select, textarea').each(function () {
153-
var ele = $(this),
154-
tagName = ele.get(0).tagName,
155-
id = getInputId(ele),
173+
var that = $(this),
174+
tag = that.get(0).tagName,
175+
id = getInputId(that),
156176
obj = $('#' + id);
157177

158178
if (values) {
159179
var val = values[index];
160180

161-
if (tagName == 'SELECT') {
181+
if (tag == 'INPUT' || tag == 'TEXTAREA') {
182+
obj.val(val);
183+
} else if (tag == 'SELECT') {
162184
if (val && val.indexOf('option')) {
163185
obj.append(val);
164186
} else {
@@ -167,12 +189,10 @@
167189
obj.val(val);
168190
}
169191
}
170-
} else {
171-
obj.val(val);
172192
}
173193
}
174194

175-
addAttribute(ele);
195+
addAttribute(that);
176196

177197
index++;
178198
});
@@ -184,7 +204,6 @@
184204
.replaceAll('%7Bmultiple_index%7D', data.currentIndex);
185205
window.eval(jsTemplate);
186206
}
187-
188207
$wrapper.data('multipleInput').currentIndex++;
189208

190209
var event = $.Event(events.afterAddRow);
@@ -211,7 +230,7 @@
211230

212231
$toDelete.fadeOut(300, function () {
213232
$(this).remove();
214-
233+
215234
event = $.Event(events.afterDeleteRow);
216235
$wrapper.trigger(event);
217236
});
@@ -230,6 +249,7 @@
230249
wrapper = ele.closest('.multiple-input').first(),
231250
form = ele.closest('form');
232251

252+
233253
// do not add attribute which are not the part of widget
234254
if (wrapper.length == 0) {
235255
return;
@@ -240,9 +260,8 @@
240260
return;
241261
}
242262

243-
var bareID = id.replace(/-\d/, '').replace(/-\d-/, '');
244-
245-
form.yiiActiveForm('add', $.extend({}, wrapper.data('multipleInput').attributes[bareID], {
263+
var data = wrapper.data('multipleInput');
264+
form.yiiActiveForm('add', $.extend({}, data.attributeDefaults, {
246265
'id': id,
247266
'input': '#' + id,
248267
'container': '.field-' + id

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/BaseColumn.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,6 @@ abstract class BaseColumn extends Object
105105
*/
106106
public $renderer;
107107

108-
/**
109-
* @var array client-side options of the attribute, e.g. enableAjaxValidation.
110-
* You can use this property for custom configuration of the column (attribute).
111-
* By default, the column will use options which are defined on widget level.
112-
*
113-
* @since 1.3
114-
*/
115-
public $attributeOptions = [];
116-
117108
/**
118109
* @var mixed the context of using a column. It is an instance of widget(MultipleInput or TabularInput).
119110
*/

0 commit comments

Comments
 (0)