@@ -58,7 +58,8 @@ $(() => {
5858 $ ( document ) . on ( 'keyup change paste' , '[data-character-count]' , ( ev ) => {
5959 const $tgt = $ ( ev . target ) ;
6060 const $counter = $ ( $tgt . attr ( 'data-character-count' ) ) ;
61- const $button = $counter . parents ( 'form' ) . find ( 'input[type="submit"],.js-suggested-edit-approve' ) ;
61+ const $form = $counter . parents ( 'form' ) ;
62+ const $button = $form . find ( 'input[type="submit"],.js-suggested-edit-approve' ) ;
6263 const $count = $counter . find ( '.js-character-count__count' ) ;
6364 const $icon = $counter . find ( '.js-character-count__icon' ) ;
6465
@@ -76,19 +77,24 @@ $(() => {
7677 if ( gtnMax || ltnMin ) {
7778 setCounterState ( $counter , 'error' ) ;
7879 setCounterIcon ( $icon , 'fa-times' ) ;
79- setSubmitButtonDisabledState ( $button , 'disabled' ) ;
8080 setInputValidationState ( $tgt , 'invalid' ) ;
8181 } else if ( gteThreshold ) {
8282 setCounterState ( $counter , 'warning' ) ;
8383 setCounterIcon ( $icon , 'fa-exclamation-circle' ) ;
84- setSubmitButtonDisabledState ( $button , 'enabled' ) ;
8584 } else {
8685 setCounterState ( $counter , 'default' ) ;
8786 setCounterIcon ( $icon , 'fa-check' ) ;
88- setSubmitButtonDisabledState ( $button , 'enabled' ) ;
8987 setInputValidationState ( $tgt , 'valid' ) ;
9088 }
9189
90+ const submittable = $form [ 0 ] ?. checkValidity ( ) ?? false ;
91+
92+ if ( ! submittable || gtnMax || ltnMin ) {
93+ setSubmitButtonDisabledState ( $button , 'disabled' ) ;
94+ } else {
95+ setSubmitButtonDisabledState ( $button , 'enabled' ) ;
96+ }
97+
9298 $count . text ( text ) ;
9399 } ) ;
94100
0 commit comments