@@ -17,6 +17,15 @@ module('Integration | Component | bs form element', function(hooks) {
1717 ]
1818 } ;
1919
20+ const nestedValidation = {
21+ nested : {
22+ name : [
23+ validatePresence ( true ) ,
24+ validateLength ( { min : 4 } )
25+ ]
26+ }
27+ } ;
28+
2029 test ( 'form is submitted if valid and validation success shown' , async function ( assert ) {
2130 let model = {
2231 name : '1234' ,
@@ -66,6 +75,31 @@ module('Integration | Component | bs form element', function(hooks) {
6675 assert . verifySteps ( [ 'Invalid action has been called.' ] ) ;
6776 } ) ;
6877
78+ test ( 'validation nested errors are shown on submit' , async function ( assert ) {
79+ let model = {
80+ nested : { name : '' }
81+ } ;
82+
83+ this . set ( 'model' , model ) ;
84+ this . set ( 'validation' , nestedValidation ) ;
85+ this . submitAction = function ( ) {
86+ assert . ok ( false , 'submit action must not been called.' ) ;
87+ } ;
88+ this . invalidAction = function ( ) {
89+ assert . step ( 'Invalid action has been called.' ) ;
90+ } ;
91+
92+ await render ( hbs `
93+ <BsForm @model={{changeset this.model this.validation}} @onSubmit={{this.submitAction}} @onInvalid={{this.invalidAction}} as |form|>
94+ <form.element @label="Name" @property="nested.name" />
95+ </BsForm>
96+ ` ) ;
97+
98+ await triggerEvent ( 'form' , 'submit' ) ;
99+ assert . dom ( 'input' ) . hasClass ( 'is-invalid' , 'input has error class' ) ;
100+ assert . verifySteps ( [ 'Invalid action has been called.' ] ) ;
101+ } ) ;
102+
69103 test ( 'validation errors are shown after blur' , async function ( assert ) {
70104 this . set ( 'model' , { name : '' } ) ;
71105 this . set ( 'validation' , validation ) ;
0 commit comments