@@ -84,23 +84,63 @@ storiesOf('Forms|Fieldset', module)
8484 </ lion-fieldset >
8585 ` ,
8686 )
87+ . add ( 'Validation' , ( ) => {
88+ function isDemoValidator ( ) {
89+ return false ;
90+ }
91+
92+ const demoValidator = ( ...factoryParams ) => [
93+ ( ...params ) => ( { validator : isDemoValidator ( ...params ) } ) ,
94+ ...factoryParams ,
95+ ] ;
96+
97+ try {
98+ localize . addData ( 'en-GB' , 'lion-validate+validator' , {
99+ error : {
100+ validator : 'Demo error message' ,
101+ } ,
102+ } ) ;
103+ } catch ( error ) {
104+ // expected as it's a demo
105+ }
106+
107+ return html `
108+ < lion-fieldset id ="someId " .errorValidators =${ [ demoValidator ( ) ] } >
109+ < lion-input name ="input1 " label ="Label "> </ lion-input >
110+ < button
111+ @click =${ ( ) => {
112+ document . getElementById ( 'someId' ) . serializeGroup ( ) ;
113+ } }
114+ >
115+ Submit
116+ </ button >
117+ </ lion-fieldset >
118+
119+ < br />
120+ < br />
121+ < button >
122+ Tab-able
123+ </ button >
124+ ` ;
125+ } )
87126 . add ( 'Validation 2 inputs' , ( ) => {
88- const input1IsTen = value => ( {
89- input1IsTen : value . input1 === 'cats' && value . input2 === 'dogs' ,
127+ const isCatsAndDogs = value => ( {
128+ isCatsAndDogs : value . input1 === 'cats' && value . input2 === 'dogs' ,
90129 } ) ;
91130 localize . locale = 'en-GB' ;
92131 try {
93- localize . addData ( 'en-GB' , 'lion-validate+input1IsTen ' , {
132+ localize . addData ( 'en-GB' , 'lion-validate+isCatsAndDogs ' , {
94133 error : {
95- input1IsTen : 'Input 1 needs to be "cats" and Input 2 needs to be "dogs"' ,
134+ isCatsAndDogs :
135+ '[Fieldset Error] Input 1 needs to be "cats" and Input 2 needs to be "dogs"' ,
96136 } ,
97137 } ) ;
98138 } catch ( error ) {
99139 // expected as it's a demo
100140 }
101141
102142 return html `
103- < lion-fieldset .errorValidators =${ [ [ input1IsTen ] ] } >
143+ < lion-fieldset .errorValidators =${ [ [ isCatsAndDogs ] ] } >
104144 < lion-input
105145 label ="An all time YouTube favorite "
106146 name ="input1 "
@@ -116,42 +156,56 @@ storiesOf('Forms|Fieldset', module)
116156 </ lion-fieldset >
117157 ` ;
118158 } )
119- . add ( 'Validation' , ( ) => {
120- function isFakeValidator ( ) {
121- return false ;
159+ . add ( 'Validation 2 fieldsets' , ( ) => {
160+ const isCats = value => ( {
161+ isCats : value . input1 === 'cats' ,
162+ } ) ;
163+ localize . locale = 'en-GB' ;
164+ try {
165+ localize . addData ( 'en-GB' , 'lion-validate+isCats' , {
166+ error : {
167+ isCats : '[Fieldset Nr. 1 Error] Input 1 needs to be "cats"' ,
168+ } ,
169+ } ) ;
170+ } catch ( error ) {
171+ // expected as it's a demo
122172 }
123173
124- const fakeValidator = ( ...factoryParams ) => [
125- ( ...params ) => ( { validator : isFakeValidator ( ...params ) } ) ,
126- ...factoryParams ,
127- ] ;
128-
174+ const isDogs = value => ( {
175+ isDogs : value . input1 === 'dogs' ,
176+ } ) ;
177+ localize . locale = 'en-GB' ;
129178 try {
130- localize . addData ( 'en-GB' , 'lion-validate+validator ' , {
179+ localize . addData ( 'en-GB' , 'lion-validate+isDogs ' , {
131180 error : {
132- validator : 'Fake error message ' ,
181+ isDogs : '[Fieldset Nr. 2 Error] Input 1 needs to be "dogs" ' ,
133182 } ,
134183 } ) ;
135184 } catch ( error ) {
136185 // expected as it's a demo
137186 }
138187
139188 return html `
140- < lion-fieldset id ="someId " .errorValidators =${ [ fakeValidator ( ) ] } >
141- < lion-input name ="input1 " label ="Label "> </ lion-input >
142- < button
143- @click =${ ( ) => {
144- document . getElementById ( 'someId' ) . serializeGroup ( ) ;
145- } }
146- >
147- Submit
148- </ button >
189+ < lion-fieldset .errorValidators =${ [ [ isCats ] ] } >
190+ < label slot ="label "> Fieldset Nr. 1</ label >
191+ < lion-input
192+ label ="An all time YouTube favorite "
193+ name ="input1 "
194+ help-text ="longer then 2 characters "
195+ .errorValidators =${ [ minLengthValidator ( 3 ) ] }
196+ > </ lion-input >
149197 </ lion-fieldset >
150-
151198 < br />
199+ < hr />
152200 < br />
153- < button >
154- Tab-able
155- </ button >
201+ < lion-fieldset .errorValidators =${ [ [ isDogs ] ] } >
202+ < label slot ="label "> Fieldset Nr. 2</ label >
203+ < lion-input
204+ label ="An all time YouTube favorite "
205+ name ="input1 "
206+ help-text ="longer then 2 characters "
207+ .errorValidators =${ [ minLengthValidator ( 3 ) ] }
208+ > </ lion-input >
209+ </ lion-fieldset >
156210 ` ;
157211 } ) ;
0 commit comments