Permalink
Browse files

Core: Fix incorrect regexp

Fixes #1200
Closes #1201
  • Loading branch information...
Damian Mooyman authored and jzaefferer committed Jul 6, 2014
1 parent 4b33a75 commit c054707d6f8828d28e73e66eeab43aba9952b06d
Showing with 22 additions and 1 deletion.
  1. +1 −1 src/core.js
  2. +21 −0 test/error-placement.js
View
@@ -770,7 +770,7 @@ $.extend( $.validator, {
// Respect existing non-error aria-describedby
if ( !describedBy ) {
describedBy = errorID;
- } else if ( !describedBy.match( new RegExp( "\b" + errorID + "\b" ) ) ) {
+ } else if ( !describedBy.match( new RegExp( "\\b" + errorID + "\\b" ) ) ) {
// Add to end of list if not already present
describedBy += " " + errorID;
}
View
@@ -310,3 +310,24 @@ test( "test existing non-error aria-describedby", function( assert ) {
strictEqual( "This is where you enter your data", $("#testForm17text-description").text() );
strictEqual( "", $("#testForm17text-error").text(), "Error label is empty for valid field" );
});
+
+test( "test pre-assigned non-error aria-describedby", function( assert ) {
+ expect( 7 );
+ var form = $( "#testForm17" ),
+ field = $( "#testForm17text" );
+
+ // Pre-assign error identifier
+ field.attr( "aria-describedby", "testForm17text-description testForm17text-error" );
+ form.validate({ errorElement: "span" });
+
+ ok( !field.valid() );
+ equal( field.attr( "aria-describedby" ), "testForm17text-description testForm17text-error" );
+ assert.hasError( field, "required" );
+
+ field.val( "foo" );
+ ok( field.valid() );
+ assert.noErrorFor( field );
+
+ strictEqual( "This is where you enter your data", $("#testForm17text-description").text() );
+ strictEqual( "", $("#testForm17text-error").text(), "Error label is empty for valid field" );
+});

0 comments on commit c054707

Please sign in to comment.