I am trying to add a custom css class to the error message. I want to make the error message red and also highlight the input element which failed the validation to red.
Code Sample :Fiddle
I have set the init to :
ko.validation.init({
grouping: { deep: true, observable: false },
decorateElement: true,
insertMessages: true,
decorateElementOnModified: true,
decorateInputElement: true,
errorClass:'error',
errorMessageClass :'error',
errorElementClass:'error'
});
But still I am not able to see the css changes
The problem is that your initKoValidation()
function is never invoked and that is because your vm.init()
is never invoked. Try this:
function vm(){
var init = function () {
initKoValidation();
}
var self = this;
self.user = ko.observable(new User());
init(); // <--- the missing piece
}