Skip to content

Commit b5cacc1

Browse files
author
Eugene Tupikov
committed
Add attributeOptions property
1 parent ea94496 commit b5cacc1

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/MultipleInput.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class MultipleInput extends InputWidget
4545
*/
4646
public $limit;
4747

48+
/**
49+
* @var array client-side attribute options, e.g. enableAjaxValidation. You may use this property in case when
50+
* you use widget without a model, since in this case widget is not able to detect client-side options
51+
* automatically.
52+
*/
53+
public $attributeOptions = [];
54+
4855
/**
4956
* @var string generated template, internal variable.
5057
*/
@@ -363,13 +370,14 @@ public function registerClientScript()
363370
MultipleInputAsset::register($view);
364371
$options = Json::encode(
365372
[
366-
'id' => $this->getId(),
367-
'template' => $this->getRowTemplate(),
368-
'jsTemplates' => $this->jsTemplates,
369-
'btnAction' => self::ACTION_REMOVE,
370-
'btnType' => 'btn-danger',
371-
'limit' => $this->limit,
372-
'replacement' => $this->replacementKeys,
373+
'id' => $this->getId(),
374+
'template' => $this->getRowTemplate(),
375+
'jsTemplates' => $this->jsTemplates,
376+
'btnAction' => self::ACTION_REMOVE,
377+
'btnType' => 'btn-danger',
378+
'limit' => $this->limit,
379+
'replacement' => $this->replacementKeys,
380+
'attributeOptions' => $this->attributeOptions,
373381
]
374382
);
375383
$id = $this->options['id'];

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020
replacement: []
2121
};
2222

23+
var defaultAttributeOptions = {
24+
enableAjaxValidation: false,
25+
validateOnBlur: false,
26+
validateOnChange: false,
27+
validateOnType: false
28+
};
29+
2330
var methods = {
2431
init: function (options) {
25-
var settings = $.extend({}, defaultOptions, options || {}),
32+
var settings = $.extend(true, {}, defaultOptions, options || {}),
2633
wrapper = $('#' + settings.id),
2734
form = wrapper.closest('form'),
2835
id = this.selector.replace('#', '');
@@ -46,14 +53,24 @@
4653
var intervalID = setInterval(function(){
4754
if (typeof form.data('yiiActiveForm') === 'object') {
4855
var attribute = form.yiiActiveForm('find', id);
56+
var attributeDefaults = [];
4957
if (typeof attribute === 'object') {
5058
$.each(attribute, function (key, value) {
5159
if (['id', 'input', 'container'].indexOf(key) == -1) {
52-
wrapper.data('multipleInput').attributeDefaults[key] = value;
60+
attributeDefaults[key] = value;
5361
}
5462
});
5563
form.yiiActiveForm('remove', id);
5664
}
65+
66+
var attributeOptions = $.extend({}, defaultAttributeOptions, settings.attributeOptions);
67+
$.each(attributeOptions, function(key, value) {
68+
if (typeof attributeDefaults[key] === 'undefined') {
69+
attributeDefaults[key] = value;
70+
}
71+
});
72+
wrapper.data('multipleInput').attributeDefaults = attributeDefaults;
73+
5774
wrapper.find('.multiple-input-list').find('input, select, textarea').each(function () {
5875
methods.addAttribute.apply(this);
5976
});
@@ -133,7 +150,8 @@
133150
return;
134151
}
135152

136-
form.yiiActiveForm('add', $.extend(wrapper.data('multipleInput').attributeDefaults, {
153+
var data = wrapper.data('multipleInput');
154+
form.yiiActiveForm('add', $.extend({}, data.attributeDefaults, {
137155
'id': id,
138156
'input': '#' + id,
139157
'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.

0 commit comments

Comments
 (0)