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" ,
@@ -63,7 +64,7 @@ export default Base.extend({
63
64
// Set ``novalidate`` attribute to disable the browser's validation
64
65
// bubbles but not disable the validation API.
65
66
this . el . setAttribute ( "novalidate" , "" ) ;
66
- } ,
67
+ }
67
68
68
69
initialize_inputs ( ) {
69
70
this . inputs = [
@@ -99,7 +100,7 @@ export default Base.extend({
99
100
( e ) => debouncer ( e )
100
101
) ;
101
102
}
102
- } ,
103
+ }
103
104
104
105
check_input ( { input, event, stop = false } ) {
105
106
if ( input . disabled ) {
@@ -320,7 +321,7 @@ export default Base.extend({
320
321
event . stopImmediatePropagation ( ) ;
321
322
}
322
323
this . set_error_message ( input ) ;
323
- } ,
324
+ }
324
325
325
326
set_validity ( { input, msg, attribute = null , min = null , max = null } ) {
326
327
// Replace some variables, as like validate.js
@@ -340,7 +341,7 @@ export default Base.extend({
340
341
// Hidden inputs do not participate in validation but we need this
341
342
// (e.g. styled date input).
342
343
input [ KEY_ERROR_MSG ] = msg ;
343
- } ,
344
+ }
344
345
345
346
remove_error ( input , all_of_group = false ) {
346
347
// Remove error message and related referencesfrom input.
@@ -365,7 +366,7 @@ export default Base.extend({
365
366
}
366
367
}
367
368
}
368
- } ,
369
+ }
369
370
370
371
set_error_message ( input ) {
371
372
this . remove_error ( input ) ;
@@ -416,10 +417,15 @@ export default Base.extend({
416
417
this . check_input ( { input : _input , stop : true } ) ;
417
418
}
418
419
}
419
- } ,
420
+ }
420
421
421
422
error_template ( message ) {
422
423
// Template for the validation message
423
424
return `<em class="validation warning message">${ message } </em>` ;
424
- } ,
425
- } ) ;
425
+ }
426
+ }
427
+
428
+ registry . register ( Pattern ) ;
429
+
430
+ export default Pattern ;
431
+ export { Pattern } ;
0 commit comments