Created
July 14, 2016 14:37
-
-
Save Zabaa/9ed7fe2d3efee611d1054537fa529184 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
function ValidationRules(viewModel) { | |
function validateInteger(value, element, param) { | |
if (!value) { | |
return false; | |
} | |
var parsedNumber = parseFloat(value); | |
if (isNaN(parsedNumber)) { | |
return false; | |
} else { | |
return (value == parsedNumber); | |
} | |
}; | |
function validateBiggestPrice(value, element, param) { | |
if (!value) { | |
return false; | |
} | |
return value > viewModel.getBiggestPrice(); | |
}; | |
this.defineValidationRules = function() { | |
$.validator.addMethod("offerPrice", $.validator.methods.required, "Należy podać cene"); | |
$.validator.addMethod("offerNumber", validateInteger, "Cena musi być liczbą"); | |
$.validator.addMethod("offerMinPrice", $.validator.methods.min, $.format("Cena musi być większa niż {0} PLN")); | |
$.validator.addMethod("offerBiggestPrice", validateBiggestPrice, "Cena musi być większa niż cena poprzedniej oferty"); | |
$.validator.addClassRules("validate-offerPrice", { offerPrice: true, offerNumber: true, offerMinPrice: 0, offerBiggestPrice: true }); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment