File tree 6 files changed +87
-23
lines changed
6 files changed +87
-23
lines changed Original file line number Diff line number Diff line change 15
15
</ head >
16
16
< body >
17
17
< div id ="app ">
18
- < validity ref ="validity " field ="select " :validators ="{
18
+ < validity ref ="validity " field ="select " v-model =" validation " :validators ="{
19
19
selected: { props: { value: { message: 'not selected item!!' } } }
20
20
} ">
21
21
< select2 :options ="options " :value ="selected " @input ="handleValidate ">
22
22
< option value ="0 "> ----- Select one -----</ option >
23
23
</ select2 >
24
24
</ validity >
25
- < p class ="errors " v-if ="result.errors "> {{result.value.selected}}</ p >
25
+ < p class ="errors " v-if ="validation. result.errors "> {{validation. result.value.selected}}</ p >
26
26
</ div >
27
27
< script >
28
28
new Vue ( {
32
32
{ id : 1 , text : 'Hello' } ,
33
33
{ id : 2 , text : 'World' }
34
34
] ,
35
- result : { }
35
+ validation : {
36
+ result : { }
37
+ }
36
38
} ,
37
39
validators : {
38
40
selected : function ( val ) {
60
62
}
61
63
} ,
62
64
mounted ( ) {
63
- var self = this
64
- var $validity = this . $refs . validity
65
- $validity . $on ( 'validate' , function ( ) {
66
- self . result = $validity . result
67
- } )
68
-
69
- $validity . validate ( )
65
+ // initial validation
66
+ this . $refs . validity . validate ( )
70
67
} ,
71
68
methods : {
72
69
handleValidate : function ( val ) {
Original file line number Diff line number Diff line change 13
13
< body >
14
14
< div id ="app ">
15
15
< label for ="language "> select your favorite programming languages</ label > < br />
16
- < validity field ="lang " :validators ="{ required: true, maxlength: 3 } ">
17
- < select multiple size ="10 " @change ="handleValidate ">
16
+ < validity ref =" validity " field ="lang " v-model =" validation " :validators ="{ required: true, maxlength: 3 } ">
17
+ < select multiple size ="10 " @change ="$refs.validity.validate() ">
18
18
< option value ="javascript "> JavaScript</ option >
19
19
< option value ="ruby "> Ruby</ option >
20
20
< option value ="python "> Python</ option >
28
28
</ select >
29
29
</ validity >
30
30
< div class ="errors ">
31
- < p v-if ="result.required "> Required !!</ p >
32
- < p v-if ="result.maxlength "> Sorry, The maximum is 3 languages !!</ p >
31
+ < p class =" required " v-if ="validation. result.required "> Required !!</ p >
32
+ < p class =" maxlength " v-if ="validation. result.maxlength "> Sorry, The maximum is 3 languages !!</ p >
33
33
</ div >
34
34
</ div >
35
35
< script >
36
36
new Vue ( {
37
- data : { result : { } } ,
38
- methods : {
39
- handleValidate : function ( e ) {
40
- var self = this
41
- var $validity = e . target . $validity
42
- $validity . validate ( function ( ) {
43
- var result = $validity . result
44
- self . result = result
45
- } )
37
+ data : {
38
+ validation : {
39
+ result : { }
46
40
}
47
41
}
48
42
} ) . $mount ( '#app' )
Original file line number Diff line number Diff line change
1
+ exports . command = function ( selector , event , cb ) {
2
+ return this . execute ( function ( selector , event , cb ) {
3
+ var e = document . createEvent ( 'HTMLEvents' )
4
+ e . initEvent ( event , true , true )
5
+ var el = document . querySelector ( selector )
6
+ el . dispatchEvent ( e )
7
+ } , [ selector , event , cb ] )
8
+ }
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ component : function ( browser ) {
3
+ browser
4
+ . url ( 'http://localhost:8080/examples/component/' )
5
+ // initial loaded
6
+ . waitForElementVisible ( '#app' , 1000 )
7
+ . waitForElementPresent ( '.errors' , 1000 )
8
+ . assert . containsText ( '.errors' , 'not selected item!!' )
9
+ // valid
10
+ . click ( '.select2-selection__rendered' )
11
+ . click ( '.select2-results__option:nth-child(2)' )
12
+ . waitForElementNotPresent ( '.errors' , 1000 )
13
+ // invalid
14
+ . click ( '.select2-selection__rendered' )
15
+ . click ( '.select2-results__option:nth-child(1)' )
16
+ . waitForElementPresent ( '.errors' , 1000 )
17
+ . assert . containsText ( '.errors' , 'not selected item!!' )
18
+ . end ( )
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ select_basic : function ( browser ) {
3
+ browser
4
+ . url ( 'http://localhost:8080/examples/select/basic/' )
5
+ // initial loaded
6
+ . waitForElementVisible ( '#app' , 1000 )
7
+ . waitForElementNotPresent ( '.errors p' , 1000 )
8
+ // valid
9
+ . click ( 'select option[value=javascript]' )
10
+ . waitForElementNotPresent ( '.errors p' , 1000 )
11
+ // invalid
12
+ . click ( 'select option[value=""]' )
13
+ . waitForElementPresent ( '.errors p' , 1000 )
14
+ . assert . containsText ( '.errors p' , 'Required !!' )
15
+ . end ( )
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ select_multiple : function ( browser ) {
3
+ browser
4
+ . url ( 'http://localhost:8080/examples/select/multiple/' )
5
+ // initial loaded
6
+ . waitForElementVisible ( '#app' , 1000 )
7
+ . waitForElementNotPresent ( '.errors .required' , 1000 )
8
+ . waitForElementNotPresent ( '.errors .maxlength' , 1000 )
9
+ // valid
10
+ . click ( 'select option[value=javascript]' )
11
+ . waitForElementNotPresent ( '.errors .required' , 1000 )
12
+ . waitForElementNotPresent ( '.errors .maxlength' , 1000 )
13
+ // invalid required
14
+ . click ( 'select option[value=javascript]' ) // not select
15
+ . waitForElementPresent ( '.errors .required' , 1000 )
16
+ . waitForElementNotPresent ( '.errors .maxlength' , 1000 )
17
+ . assert . containsText ( '.errors .required' , 'Required !!' )
18
+ // invalid maxlength
19
+ . click ( 'select option[value=javascript]' )
20
+ . click ( 'select option[value=go]' )
21
+ . click ( 'select option[value=lua]' )
22
+ . click ( 'select option[value=ruby]' )
23
+ . waitForElementNotPresent ( '.errors .required' , 1000 )
24
+ . waitForElementPresent ( '.errors .maxlength' , 1000 )
25
+ . assert . containsText ( '.errors .maxlength' , 'Sorry, The maximum is 3 languages !!' )
26
+ . end ( )
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments