Skip to content

Commit 6d612c8

Browse files
committed
added method to set value of an particular option
1 parent 3b597af commit 6d612c8

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Yii2 multiple input change log
77
- Renamed `limit` option to `max`
88
- Changed namespace from `unclead\widgets` to `yii\multipleinout`
99
- #92: Adjustments for correct work with AR relations
10+
- Enh #104: Added method to set value of an particular option
1011

1112
1.4.1
1213
=====

docs/javascript.md

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,54 @@ jQuery('#multiple-input').on('afterInit', function(){
2727

2828
#JavaScript operations
2929

30-
Dynamically operations in widget:
31-
- `add`: adding new row, **param** *object*: object with values for inputs, can be filled with <option> tags for dynamically added options for select (for ajax select).
32-
- `remove`: remove row, **param** *integer*: row number for removing, if not specified then removes last row.
33-
- `clear`: remove all rows
30+
####add
3431

35-
**Examples**
32+
Adding new row with specified settings.
33+
34+
Input arguments:
35+
- *object* - values for inputs, can be filled with <option> tags for dynamically added options for select (for ajax select).
36+
37+
Example:
3638

3739
```js
3840
$('#multiple-input').multipleInput('add', {first: 10, second: '<option value="2" selected="selected">second</option>'});
41+
```
42+
43+
####remove
44+
45+
Remove row with specified index.
46+
47+
Inout arguments:
48+
- *integer* - row number for removing, if not specified then removes last row.
49+
50+
Example:
51+
52+
```js
3953
$('#multiple-input').multipleInput('remove', 2);
54+
```
55+
56+
####clear
57+
58+
Remove all rows
59+
60+
```js
4061
$('#multiple-input').multipleInput('clear');
41-
```
62+
```
63+
64+
####option
65+
66+
Get or set a particular option
67+
68+
Input arguments:
69+
- *string* - a name of an option
70+
- *mixed* - a value of an option (optional). If specified will be used as a new value of an option;
71+
72+
Example:
73+
74+
```js
75+
$('#multiple-input').multipleInput('option', 'max');
76+
$('#multiple-input').multipleInput('option', 'max', 10);
77+
78+
```
79+
80+

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@
167167
$('.js-input-remove').each(function () {
168168
removeInput($(this));
169169
});
170+
},
171+
172+
option: function(name, value) {
173+
value = value || null;
174+
175+
var data = $(this).data('multipleInput'),
176+
settings = data.settings;
177+
if (value === null) {
178+
if (!settings.hasOwnProperty(name)) {
179+
throw new Error('Option "' + name + '" does not exist');
180+
}
181+
return settings[name];
182+
} else if (settings.hasOwnProperty(name)) {
183+
settings[name] = value;
184+
data.settings = settings;
185+
$(this).data('multipleInput', data);
186+
}
170187
}
171188
};
172189

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)