This repository was archived by the owner on Nov 22, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ export class Form extends Screen {
76
76
77
77
// Bye!
78
78
this . end ( 'form submission' )
79
+ } else {
80
+ // Mark form(s) as validated, but leave
81
+ // the display unchanged otherwise
82
+ this . options . el . querySelectorAll ( 'form' )
83
+ . forEach ( f => f . setAttribute ( 'data-labjs-validated' , '' ) )
79
84
}
80
85
81
86
// Prevent default form behavior
Original file line number Diff line number Diff line change @@ -256,6 +256,12 @@ describe('HTML-based components', () => {
256
256
return p
257
257
} )
258
258
259
+ // Validation --------------------------------------------------------------
260
+ const minimalInvalidForm = '' +
261
+ '<form>' +
262
+ ' <input type="text" name="text_input" required>' +
263
+ '</form>'
264
+
259
265
it ( 'validates form input using a validation function' , ( ) => {
260
266
f . options . el . innerHTML = '' +
261
267
'<form>' +
@@ -270,10 +276,7 @@ describe('HTML-based components', () => {
270
276
} )
271
277
272
278
it ( 'is also sensitive to native form validation' , ( ) => {
273
- f . options . el . innerHTML = '' +
274
- '<form>' +
275
- ' <input type="text" name="text_input" required>' +
276
- '</form>'
279
+ f . options . el . innerHTML = minimalInvalidForm
277
280
278
281
assert . notOk ( f . validate ( ) )
279
282
@@ -284,6 +287,19 @@ describe('HTML-based components', () => {
284
287
285
288
assert . ok ( f . validate ( ) )
286
289
} )
290
+
291
+ it ( 'adds data-labjs-validated attribute after failed validation' , ( ) => {
292
+ f . options . content = minimalInvalidForm
293
+
294
+ return f . run ( ) . then ( ( ) => {
295
+ f . submit ( )
296
+ assert . equal (
297
+ f . options . el . querySelector ( 'form' )
298
+ . getAttribute ( 'data-labjs-validated' ) ,
299
+ '' ,
300
+ )
301
+ } )
302
+ } )
287
303
} )
288
304
289
305
describe ( 'Frame' , ( ) => {
You can’t perform that action at this time.
0 commit comments