11// Patterns validate - Form vlidation
22import "../../core/polyfills" ; // SubmitEvent.submitter for Safari < 15.4 and jsDOM
33import $ from "jquery" ;
4- import Base from "../../core/base " ;
4+ import { BasePattern } from "../../core/basepattern " ;
55import Parser from "../../core/parser" ;
66import dom from "../../core/dom" ;
77import events from "../../core/events" ;
88import logging from "../../core/logging" ;
99import utils from "../../core/utils" ;
10+ import registry from "../../core/registry" ;
1011
1112const logger = logging . getLogger ( "pat-validation" ) ;
1213//logger.setLevel(logging.Level.DEBUG);
@@ -34,12 +35,12 @@ parser.addArgument("error-template");
3435const KEY_ERROR_EL = "__patternslib__input__error__el" ;
3536const KEY_ERROR_MSG = "__patternslib__input__error__msg" ;
3637
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 ;
4042
4143 init ( ) {
42- this . options = parser . parse ( this . el , this . options ) ;
4344 events . add_event_listener (
4445 this . el ,
4546 "submit" ,
@@ -63,7 +64,7 @@ export default Base.extend({
6364 // Set ``novalidate`` attribute to disable the browser's validation
6465 // bubbles but not disable the validation API.
6566 this . el . setAttribute ( "novalidate" , "" ) ;
66- } ,
67+ }
6768
6869 initialize_inputs ( ) {
6970 this . inputs = [
@@ -99,7 +100,7 @@ export default Base.extend({
99100 ( e ) => debouncer ( e )
100101 ) ;
101102 }
102- } ,
103+ }
103104
104105 check_input ( { input, event, stop = false } ) {
105106 if ( input . disabled ) {
@@ -320,7 +321,7 @@ export default Base.extend({
320321 event . stopImmediatePropagation ( ) ;
321322 }
322323 this . set_error_message ( input ) ;
323- } ,
324+ }
324325
325326 set_validity ( { input, msg, attribute = null , min = null , max = null } ) {
326327 // Replace some variables, as like validate.js
@@ -340,7 +341,7 @@ export default Base.extend({
340341 // Hidden inputs do not participate in validation but we need this
341342 // (e.g. styled date input).
342343 input [ KEY_ERROR_MSG ] = msg ;
343- } ,
344+ }
344345
345346 remove_error ( input , all_of_group = false ) {
346347 // Remove error message and related referencesfrom input.
@@ -365,7 +366,7 @@ export default Base.extend({
365366 }
366367 }
367368 }
368- } ,
369+ }
369370
370371 set_error_message ( input ) {
371372 this . remove_error ( input ) ;
@@ -416,10 +417,15 @@ export default Base.extend({
416417 this . check_input ( { input : _input , stop : true } ) ;
417418 }
418419 }
419- } ,
420+ }
420421
421422 error_template ( message ) {
422423 // Template for the validation message
423424 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