Created
October 22, 2011 19:50
-
-
Save timhobbs/1306413 to your computer and use it in GitHub Desktop.
MaximumWeightAttribute custom attribute jQuery unobtrusive client side validation implementation
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
<script type="text/javascript"> | |
$.validator.addMethod("maximumweight", | |
function (value, element, parameters) { | |
var carrier = $("#" + parameters["dependentproperty"]).val(); | |
var carriervalue = parameters["dependentvalue"].toString(); | |
var weightvalue = Number(parameters["weightvalue"]); | |
if (carrier == carriervalue && value > weightvalue) { | |
return false; | |
} | |
return true; | |
} | |
); | |
$.validator.unobtrusive.adapters.add( | |
"maximumweight", | |
["weightvalue", "dependentproperty", "dependentvalue"], | |
function (options) { | |
options.rules["maximumweight"] = { | |
weightvalue: options.params["weightvalue"], | |
dependentproperty: options.params["dependentproperty"], | |
dependentvalue: options.params["dependentvalue"] | |
}; | |
options.messages["maximumweight"] = options.message; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment