Skip to content

Commit

Permalink
Merge pull request #9 from DoSomething/validation-olé
Browse files Browse the repository at this point in the history
Little hacky hotfix for DoSomething/legacy-website#5759.
  • Loading branch information
DFurnes committed Nov 11, 2015
2 parents 68a2420 + dd07a45 commit 6e788f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dosomething-validation",
"version": "0.2.1",
"version": "0.2.2",
"license": "MIT",
"engines": {
"node": "0.10.x"
Expand Down Expand Up @@ -36,11 +36,10 @@
"grunt-contrib-watch": "^0.6.1",
"grunt-modernizr": "^0.6.0",
"grunt-postcss": "^0.2.0",
"grunt-sass": "^0.18.0",
"grunt-sass": "^1.1.0",
"grunt-webpack": "^1.0.8",
"jshint-stylish": "^1.0.0",
"load-grunt-tasks": "^3.1.0",
"neue": "DoSomething/neue#v6.3.0",
"qunitjs": "^1.17.1",
"time-grunt": "^1.0.0",
"webpack": "^1.4.5",
Expand Down
9 changes: 5 additions & 4 deletions src/validation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals Drupal */

/**
* Client-side form validation logic. Form element is validated based
* on `data-validate` attribute, and validation output is placed in
Expand All @@ -19,7 +21,6 @@ import $ from "jquery";
import Events from "./events";
var validations = [];


/**
* Returns whether element is <input>, <select>, or <textarea>.
* @param {jQuery} $el Element to check type of.
Expand Down Expand Up @@ -68,7 +69,7 @@ var showValidationMessage = function($field, result) {
}

if(result.suggestion) {
$fieldMessage.html("Did you mean " + result.suggestion.full + "? <a href='#' data-suggestion='" + result.suggestion.full + "'class='js-mailcheck-fix'>Fix it!</a>");
$fieldMessage.html(Drupal.t("Did you mean") + " " + result.suggestion.full + "? <a href='#' data-suggestion='" + result.suggestion.full + "'class='js-mailcheck-fix'>" + Drupal.t("Fix it!") + "</a>");
Events.publish("Validation:Suggestion", result.suggestion.domain);
}

Expand Down Expand Up @@ -330,12 +331,12 @@ registerValidationFunction("match", function(string, secondString, done) {
if(string === secondString && string !== "") {
return done({
success: true,
message: "Looks good!"
message: Drupal.t("Looks good!")
});
} else {
return done({
success: false,
message: "That doesn't match."
message: Drupal.t("That doesn't match.")
});
}
});
Expand Down
7 changes: 7 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
module("Validation");

test("Match", function() {

// Stub Drupal.t
window.Drupal = {};
window.Drupal.t = function(string) {
return string;
};

DSValidation.Validations.match.fn("dog", "cat", function(result) {
ok(result.success == false, "should reject if different strings");
});
Expand Down

0 comments on commit 6e788f7

Please sign in to comment.