1
1
// Patterns validate - Form vlidation
2
2
import "../../core/polyfills" ; // SubmitEvent.submitter for Safari < 15.4 and jsDOM
3
3
import $ from "jquery" ;
4
- import Base from "../../core/base " ;
4
+ import { BasePattern } from "../../core/basepattern " ;
5
5
import Parser from "../../core/parser" ;
6
6
import dom from "../../core/dom" ;
7
7
import events from "../../core/events" ;
8
8
import logging from "../../core/logging" ;
9
9
import utils from "../../core/utils" ;
10
+ import registry from "../../core/registry" ;
10
11
11
12
const logger = logging . getLogger ( "pat-validation" ) ;
12
13
//logger.setLevel(logging.Level.DEBUG);
@@ -34,12 +35,12 @@ parser.addArgument("error-template");
34
35
const KEY_ERROR_EL = "__patternslib__input__error__el" ;
35
36
const KEY_ERROR_MSG = "__patternslib__input__error__msg" ;
36
37
37
- export default Base . extend ( {
38
- name : "validation" ,
39
- trigger : "form.pat-validation" ,
38
+ class Pattern extends BasePattern {
39
+ static name = "validation" ;
40
+ static trigger = "form.pat-validation" ;
41
+ static parser = parser ;
40
42
41
43
init ( ) {
42
- this . options = parser . parse ( this . el , this . options ) ;
43
44
events . add_event_listener (
44
45
this . el ,
45
46
"submit" ,
@@ -52,7 +53,11 @@ export default Base.extend({
52
53
logger . debug ( "Checking input for submit" , input , e ) ;
53
54
this . check_input ( { input : input , event : e } ) ;
54
55
}
55
- }
56
+ } ,
57
+ // Make sure this event handler is run early, in the capturing
58
+ // phase in order to be able to cancel later non-capturing submit
59
+ // events.
60
+ { capture : true }
56
61
) ;
57
62
58
63
this . initialize_inputs ( ) ;
@@ -63,7 +68,7 @@ export default Base.extend({
63
68
// Set ``novalidate`` attribute to disable the browser's validation
64
69
// bubbles but not disable the validation API.
65
70
this . el . setAttribute ( "novalidate" , "" ) ;
66
- } ,
71
+ }
67
72
68
73
initialize_inputs ( ) {
69
74
this . inputs = [
@@ -99,7 +104,7 @@ export default Base.extend({
99
104
( e ) => debouncer ( e )
100
105
) ;
101
106
}
102
- } ,
107
+ }
103
108
104
109
check_input ( { input, event, stop = false } ) {
105
110
if ( input . disabled ) {
@@ -320,7 +325,7 @@ export default Base.extend({
320
325
event . stopImmediatePropagation ( ) ;
321
326
}
322
327
this . set_error_message ( input ) ;
323
- } ,
328
+ }
324
329
325
330
set_validity ( { input, msg, attribute = null , min = null , max = null } ) {
326
331
// Replace some variables, as like validate.js
@@ -340,7 +345,7 @@ export default Base.extend({
340
345
// Hidden inputs do not participate in validation but we need this
341
346
// (e.g. styled date input).
342
347
input [ KEY_ERROR_MSG ] = msg ;
343
- } ,
348
+ }
344
349
345
350
remove_error ( input , all_of_group = false ) {
346
351
// Remove error message and related referencesfrom input.
@@ -365,7 +370,7 @@ export default Base.extend({
365
370
}
366
371
}
367
372
}
368
- } ,
373
+ }
369
374
370
375
set_error_message ( input ) {
371
376
this . remove_error ( input ) ;
@@ -416,10 +421,15 @@ export default Base.extend({
416
421
this . check_input ( { input : _input , stop : true } ) ;
417
422
}
418
423
}
419
- } ,
424
+ }
420
425
421
426
error_template ( message ) {
422
427
// Template for the validation message
423
428
return `<em class="validation warning message">${ message } </em>` ;
424
- } ,
425
- } ) ;
429
+ }
430
+ }
431
+
432
+ registry . register ( Pattern ) ;
433
+
434
+ export default Pattern ;
435
+ export { Pattern } ;
0 commit comments