-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial ARIA-Required implementation
Add aria-required tags to any of the data, static or class required elements. Dynamic validation for rules added through the form.validate rules object do not get picked up till first run.
- Loading branch information
1 parent
4f8a631
commit bf3cfb2
Showing
3 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,76 @@ | ||
module("aria"); | ||
|
||
test("Invalid field adds aria-invalid=true", function() { | ||
var ariafirstname = $('#ariafirstname'); | ||
var ariaInvalidFirstName = $('#ariaInvalidFirstName'); | ||
var form = $('#ariaInvalid'); | ||
form.validate({ | ||
rules: { | ||
ariafirstname: 'required' | ||
ariaInvalidFirstName: 'required' | ||
} | ||
}); | ||
ariafirstname.val(''); | ||
ariafirstname.valid(); | ||
equal(ariafirstname.attr('aria-invalid'), "true"); | ||
ariaInvalidFirstName.val(''); | ||
ariaInvalidFirstName.valid(); | ||
equal(ariaInvalidFirstName.attr('aria-invalid'), "true"); | ||
}); | ||
|
||
test("Valid field adds aria-invalid=false", function() { | ||
var ariafirstname = $('#ariafirstname'); | ||
var ariaInvalidFirstName = $('#ariaInvalidFirstName'); | ||
var form = $("#ariaInvalid"); | ||
form.validate({ | ||
rules: { | ||
ariafirstname: "required" | ||
ariaInvalidFirstName: "required" | ||
} | ||
}); | ||
ariafirstname.val('not empty'); | ||
ariafirstname.valid(); | ||
equal(ariafirstname.attr("aria-invalid"), "false"); | ||
ariaInvalidFirstName.val('not empty'); | ||
ariaInvalidFirstName.valid(); | ||
equal(ariaInvalidFirstName.attr("aria-invalid"), "false"); | ||
equal($("#ariaInvalid [aria-invalid=false]").length, 1); | ||
}); | ||
|
||
test("resetForm(): removes all aria-invalid attributes", function() { | ||
var ariafirstname = $('#ariafirstname'); | ||
var ariaInvalidFirstName = $('#ariaInvalidFirstName'); | ||
var form = $("#ariaInvalid"); | ||
var validator = form.validate({ | ||
rules: { | ||
ariafirstname: "required" | ||
ariaInvalidFirstName: "required" | ||
} | ||
}); | ||
ariafirstname.val('not empty'); | ||
ariafirstname.valid(); | ||
ariaInvalidFirstName.val('not empty'); | ||
ariaInvalidFirstName.valid(); | ||
validator.resetForm(); | ||
equal($("#ariaInvalid [aria-invalid]").length, 0, "resetForm() should remove any aria-invalid attributes"); | ||
}); | ||
|
||
test("Static required field adds aria-required", function() { | ||
var ariaRequiredStatic = $('#ariaRequiredStatic'); | ||
var form = $("#ariaRequired"); | ||
form.validate(); | ||
equal(ariaRequiredStatic.attr("aria-required"), "true"); | ||
}); | ||
|
||
test("Data required field adds aria-required", function() { | ||
var ariaRequiredData = $('#ariaRequiredData'); | ||
var form = $("#ariaRequired"); | ||
form.validate(); | ||
equal(ariaRequiredData.attr("aria-required"), "true"); | ||
}); | ||
|
||
test("Class required field adds aria-required", function() { | ||
var ariaRequiredClass = $('#ariaRequiredClass'); | ||
var form = $("#ariaRequired"); | ||
form.validate(); | ||
equal(ariaRequiredClass.attr("aria-required"), "true"); | ||
}); | ||
|
||
test("Dynamically required field adds aria-required after valid()", function() { | ||
var ariaRequiredDynamic = $('#ariaRequiredDynamic'); | ||
var form = $("#ariaRequired"); | ||
form.resetForm(); | ||
form.validate({ | ||
rules: { | ||
ariaRequiredDynamic: "required" | ||
} | ||
}); | ||
ariaRequiredDynamic.valid(); | ||
equal(ariaRequiredDynamic.attr("aria-required"), "true"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters