Created
October 14, 2010 20:10
-
-
Save devth/626947 to your computer and use it in GitHub Desktop.
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
$("input.dollars, input.number, input.percentage").blur(function(){ | |
// VALIDATE | |
var input = $(this); | |
if (input.val() == "") input.val("0"); | |
if (input.attr("data-min") != undefined && input.attr("data-max") != undefined){ | |
var min = parseInt(input.attr("data-min")); | |
var max = parseInt(input.attr("data-max")); | |
var val = parseInt(input.val()); | |
if ( val < min || val > max ){ | |
input.addClass('error'); | |
var minmax = { min:min, max:max }; | |
var warning = input.closest('.formRow').find('.warning'); | |
var errors = { | |
percentage: "Value must be between {min} and {max}%", | |
dollars: "Value must be between ${min} and ${max}", | |
number: "Value must be between {min} and {max}" | |
}; | |
warning.text( errors[input.attr("data-type")].supplant(minmax) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment