File tree Expand file tree Collapse file tree 5 files changed +50
-8
lines changed Expand file tree Collapse file tree 5 files changed +50
-8
lines changed Original file line number Diff line number Diff line change 1
- Yii2 Multiple input widget.
2
- ==================
1
+ #Yii2 Multiple input widget.
3
2
Yii2 widget for handle multiple inputs for an attribute of model
4
3
5
- Installation
6
- ------------
4
+ ## Installation
5
+
7
6
8
7
The preferred way to install this extension is through [ composer] ( http://getcomposer.org/download/ ) .
9
8
@@ -21,8 +20,10 @@ or add
21
20
22
21
to the require section of your ` composer.json ` file.
23
22
24
- Usage:
25
- ------
26
- Look at examples for getting more details
23
+ ##Usage
24
+
25
+
26
+ Widget supports several use cases. Use the following links for getting more information
27
27
28
- Full documentation in progress.
28
+ - [ Single column example] ( docs/single_column.md )
29
+ - [ Several columns example] ( docs/several_columns.md )
Original file line number Diff line number Diff line change
1
+ #Several columns example
2
+
3
+ TBD
Original file line number Diff line number Diff line change
1
+ #Single column example
2
+
3
+ For example your application contains the model ` User ` that has the related model ` UserEmail `
4
+ You can add virtual attribute ` emails ` for collect emails from form and then you can save them to database.
5
+
6
+ In this case you can use ` yii2-multiple-input ` widget for supporting multiple inputs how to describe below.
7
+
8
+ First of all we have to declare virtual attribute in model
9
+
10
+ ```
11
+ class ExampleModel extends Model
12
+ {
13
+ /**
14
+ * @var array virtual attribute for keeping emails
15
+ */
16
+ public $emails;
17
+ ```
Original file line number Diff line number Diff line change @@ -15,10 +15,21 @@ class ExampleModel extends Model
15
15
const TYPE_EMAIL = 'email ' ;
16
16
const TYPE_PHONE = 'phone ' ;
17
17
18
+ /**
19
+ * @var array virtual attribute for keeping emails
20
+ */
18
21
public $ emails ;
19
22
23
+ /**
24
+ * @var
25
+ */
20
26
public $ phones ;
21
27
28
+ /**
29
+ * @var
30
+ */
31
+ public $ schedule ;
32
+
22
33
23
34
public function rules ()
24
35
{
@@ -43,6 +54,11 @@ public function scenarios()
43
54
];
44
55
}
45
56
57
+ /**
58
+ * Phone number validation
59
+ *
60
+ * @param $attribute
61
+ */
46
62
public function validatePhones ($ attribute )
47
63
{
48
64
$ items = $ this ->$ attribute ;
@@ -68,6 +84,11 @@ public function validatePhones($attribute)
68
84
}
69
85
}
70
86
87
+ /**
88
+ * Email validation.
89
+ *
90
+ * @param $attribute
91
+ */
71
92
public function validateEmails ($ attribute )
72
93
{
73
94
$ items = $ this ->$ attribute ;
You can’t perform that action at this time.
0 commit comments