@@ -620,6 +620,73 @@ describe("pat-validation", function () {
620620 expect ( document . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
621621 expect ( document . querySelector ( "em.warning" ) . matches ( "input[name=input2] + em.warning" ) ) . toBe ( true ) ;
622622 } ) ;
623+
624+ it ( "1.25 - Can combine multiple custom validation rules." , async function ( ) {
625+ document . body . innerHTML = `
626+ <form
627+ class="pat-validation"
628+ data-pat-validation="
629+ message-required: is required;
630+ message-equality: not equal;
631+ message-min-values: too few;
632+ "
633+ >
634+ <fieldset data-pat-validation="min-values: 2">
635+ <input id="i1" name="textinput" data-pat-validation="equality: extrainput" required>
636+ <input id="i2" name="textinput">
637+ </fieldset>
638+ <input id="i3" name="extrainput">
639+ </form>
640+ ` ;
641+ const form = document . querySelector ( ".pat-validation" ) ;
642+ const input1 = document . querySelector ( "#i1" ) ;
643+ const input2 = document . querySelector ( "#i2" ) ;
644+ const input3 = document . querySelector ( "#i3" ) ;
645+ const button = document . querySelector ( "button" ) ;
646+
647+ const instance = new Pattern ( form ) ;
648+ await events . await_pattern_init ( instance ) ;
649+
650+ input1 . dispatchEvent ( events . change_event ( ) ) ;
651+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
652+
653+ // form is invalid due to input1's required attribute
654+ expect ( input1 . matches ( ":invalid" ) ) . toBe ( true ) ;
655+ expect ( document . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
656+ expect ( document . querySelectorAll ( "em.warning" ) [ 0 ] . textContent ) . toBe (
657+ "is required"
658+ ) ;
659+
660+ input1 . value = "ok" ;
661+ input1 . dispatchEvent ( events . change_event ( ) ) ;
662+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
663+
664+ // form is invalid due to input1's equality constraint
665+ expect ( input1 . matches ( ":invalid" ) ) . toBe ( true ) ;
666+ expect ( document . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
667+ expect ( document . querySelectorAll ( "em.warning" ) [ 0 ] . textContent ) . toBe (
668+ "not equal"
669+ ) ;
670+
671+ input3 . value = "ok" ;
672+ input1 . dispatchEvent ( events . change_event ( ) ) ;
673+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
674+
675+ // form is invalid due to input1's equality constraint
676+ expect ( input1 . matches ( ":invalid" ) ) . toBe ( true ) ;
677+ expect ( document . querySelectorAll ( "em.warning" ) . length ) . toBe ( 1 ) ;
678+ expect ( document . querySelectorAll ( "em.warning" ) [ 0 ] . textContent ) . toBe (
679+ "too few"
680+ ) ;
681+
682+ input2 . value = "ok" ;
683+ form . dispatchEvent ( events . submit_event ( ) ) ;
684+ await utils . timeout ( 1 ) ; // wait a tick for async to settle.
685+
686+ // form is now valid.
687+ expect ( input1 . matches ( ":invalid" ) ) . toBe ( false ) ;
688+ expect ( document . querySelectorAll ( "em.warning" ) . length ) . toBe ( 0 ) ;
689+ } ) ;
623690 } ) ;
624691
625692 describe ( "2 - required inputs" , function ( ) {
0 commit comments