Validate: need dynamic message on failed validation
I need to include the contents of a field in a validation error message.
I tried using a closure around the addMethod call as demonstrated in the code below, but that does not work. Is there a way to do this?
Thanks!
- (function() {
- var msg = "Closed items cannot be linked to items of type ";
- jQuery.validator.addMethod("closedLinkRestriction",
- function(value, element) {
- if (value === undefined || value === '') return true;
- var selectedType = getExtendedLookupData($("#TypeLookup").data('lookupData'), element);
- if (selectedType.CanLinkToClosedItems) {
- msg += $.trim(selectedType.Description) + '.';
- return false;
- }
- else {
- return true;
- }
- },
- msg
- );
- })();