mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-12 12:10:44 +08:00
Update jquery.validation bindings and tests. Changes include:
* Relaxed $.validator.format so that the arguments don't have to be strings. Added overloads, so that if called with just a template and no arguments, it returns a curried function, as per http://jqueryvalidation.org/category/validator/. $.format might need changing (?) but I haven't touched it as it's deprecated anyway. Added tests. * Place everything inside a JQueryValidation module to avoid cluttering the global namespace * Split Validator into Validator and ValidatorStatic interfaces for correctness. Subdivide tests accordingly. * Change rules to be typed as a RulesDictionary rather than an Object. * Change ValidationOptions.groups to be { [groupName: string]: string } rather than Object. * Change ValidationOptions.onclick, onfocusout and onkeyup from bool | Function to ShouldValidatePredicate, an alias for boolean | ((element: HTMLElement, event: JQueryEventObject) => void). Added more tests
This commit is contained in:
@@ -77,6 +77,17 @@ function test_validate() {
|
||||
$(".selector").validate({
|
||||
onclick: false
|
||||
});
|
||||
$(".selector").validate({
|
||||
onfocusout: (elt) => { },
|
||||
onkeyup: (elt) => { },
|
||||
onclick: (elt) => { }
|
||||
});
|
||||
$(".selector").validate({
|
||||
onfocusout: (elt, event) => { },
|
||||
onkeyup: (elt, event) => { },
|
||||
onclick: (elt, event) => { }
|
||||
});
|
||||
|
||||
$(".selector").validate({
|
||||
focusInvalid: false
|
||||
});
|
||||
@@ -111,7 +122,7 @@ function test_validate() {
|
||||
submitHandler: function () { alert("Submitted!") }
|
||||
});
|
||||
$(".selector").validate({
|
||||
showErrors: function (errorMap: ErrorDictionary, errorList: ErrorListItem[]) {
|
||||
showErrors: function (errorMap: JQueryValidation.ErrorDictionary, errorList: JQueryValidation.ErrorListItem[]) {
|
||||
$("#summary").html("Your form contains " + this.numberOfInvalids() + " errors, see details below.");
|
||||
this.defaultShowErrors();
|
||||
}
|
||||
@@ -154,6 +165,18 @@ function test_validate() {
|
||||
$(".selector").validate({
|
||||
ignoreTitle: true
|
||||
});
|
||||
// onSubmit, onfocusout, onkeyup, onclick
|
||||
$('.selector').validate({
|
||||
onsubmit: false,
|
||||
onfocusout: false,
|
||||
onkeyup: false,
|
||||
onclick: false,
|
||||
});
|
||||
$('.selector').validate({
|
||||
onfocusout: () => {},
|
||||
onkeyup: () => {},
|
||||
onclick: function(elt) { return 2; }
|
||||
});
|
||||
}
|
||||
|
||||
function test_methods() {
|
||||
@@ -194,10 +217,15 @@ function test_methods() {
|
||||
validator.hideErrors();
|
||||
var isValid: boolean = validator.valid();
|
||||
var size: number = validator.size();
|
||||
var errorMap: ErrorDictionary = validator.errorMap;
|
||||
var errorList: ErrorListItem[] = validator.errorList;
|
||||
var errorMap: JQueryValidation.ErrorDictionary = validator.errorMap;
|
||||
var errorList: JQueryValidation.ErrorListItem[] = validator.errorList;
|
||||
|
||||
$("#summary").text(validator.numberOfInvalids() + " field(s) are invalid");
|
||||
var invalidElements: HTMLElement[] = validator.invalidElements();
|
||||
var validElements: HTMLElement[] = validator.validElements();
|
||||
}
|
||||
|
||||
function test_static_methods() {
|
||||
jQuery.validator.setDefaults({
|
||||
debug: true
|
||||
});
|
||||
@@ -228,6 +256,11 @@ function test_methods() {
|
||||
maxlength: 5
|
||||
}
|
||||
});
|
||||
var invalidElements: HTMLElement[] = validator.invalidElements();
|
||||
var validElements: HTMLElement[] = validator.validElements();
|
||||
|
||||
// jQuery.validator.format
|
||||
jQuery.validator.format('{0}');
|
||||
jQuery.validator.format('{0} {1}')('a', 2);
|
||||
jQuery.validator.format('{0} {1}', 'a', 2);
|
||||
jQuery.validator.format('{0} {1}', ['a', 2]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user