aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/static/new/packages/ValidationPlugin/test/messages.js
blob: 10b4fde8f13211e84b249542cba2fcae4fac06d3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module("messages");

test("predefined message not overwritten by addMethod(a, b, undefined)", function() {
	var message = "my custom message";
	$.validator.messages.custom = message;
	$.validator.addMethod("custom", function() {});
	deepEqual(message, $.validator.messages.custom);
	delete $.validator.messages.custom;
	delete $.validator.methods.custom;
});

test("group error messages", function() {
	$.validator.addClassRules({
		requiredDateRange: { required: true, date: true, dateRange: true }
	});
	$.validator.addMethod("dateRange", function() {
		return new Date($("#fromDate").val()) < new Date($("#toDate").val());
	}, "Please specify a correct date range.");
	var form = $("#dateRangeForm");
	form.validate({
		groups: {
			dateRange: "fromDate toDate"
		},
		errorPlacement: function(error) {
			form.find(".errorContainer").append(error);
		}
	});
	ok( !form.valid() );
	equal( 1, form.find(".errorContainer *").length );
	equal( "Please enter a valid date.", form.find(".errorContainer .error:not(input)").text() );

	$("#fromDate").val("12/03/2006");
	$("#toDate").val("12/01/2006");
	ok( !form.valid() );
	equal( "Please specify a correct date range.", form.find(".errorContainer .error:not(input)").text() );

	$("#toDate").val("12/04/2006");
	ok( form.valid() );
	ok( form.find(".errorContainer .error:not(input)").is(":hidden") );
});

test("read messages from metadata", function() {
	var form = $("#testForm9"),
		e, g;

	form.validate();
	e = $("#testEmail9");
	e.valid();
	equal( form.find("#testEmail9").next(".error:not(input)").text(), "required" );
	e.val("bla").valid();
	equal( form.find("#testEmail9").next(".error:not(input)").text(), "email" );

	g = $("#testGeneric9");
	g.valid();
	equal( form.find("#testGeneric9").next(".error:not(input)").text(), "generic");
	g.val("bla").valid();
	equal( form.find("#testGeneric9").next(".error:not(input)").text(), "email" );
});

test("read messages from metadata, with meta option specified, but no metadata in there", function() {
	var form = $("#testForm1clean");
	form.validate({
		meta: "validate",
		rules: {
			firstnamec: "required"
		}
	});
	ok(!form.valid(), "not valid");
});