Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom validation messages without pattern #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
/* falls through */
case "checkbox":
if (required && !this.get("checked")) {
errors.push("field is required");
errors.push(this.get("title") || "field is required");
}
break;

Expand All @@ -116,13 +116,13 @@
msg = this.get("title") || "illegal value format";
} else {
regexp = patterns[type];
msg = I18N_MISMATCH[type];
msg = this.get("title") || I18N_MISMATCH[type];
}
}

if (required && !regexp) {
regexp = patterns.required;
msg = "field is required";
msg = this.get("title") || "field is required";
}

if (regexp && !regexp.test(value)) {
Expand Down
11 changes: 11 additions & 0 deletions test/forms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ describe("forms", function() {
expect(spy).toHaveBeenCalled();
});*/


it("should allow custom tooltip messages via the title attribute", function() {
var ValiditySpy = spyOn(window, 'Validity');
var form = DOM.mock("form>input[type=text name=d title=customerror");
DOM.find("body").append(form);

expect(form).toBeValid();

expect(ValiditySpy).toHaveBeenCalledWith(["customerror"]);
});

it("should allow to add custom validation", function() {
var form = DOM.mock("form>input[type=text name=d]");

Expand Down