cannot convert to object
- by Dazz
if i execute the following code i get a cannot convert to object error;
Uncaught exception: TypeError: Cannot convert 'validation.messages.field' to object
$.fn.validate = function(validation) {
$.each(validation.rules, function(field, fieldRules){
$.each(fieldRules, function(rule, ruleValue){
var fieldValue = $('[name=' + field + ']').val();
if (eval(rule + '(fieldValue, ruleValue)') == false){
alert(validation.rules.field.rule);
return false;
}else{
return true;
};
});
});
}
the problem is the
alert(validation.messages.field.rule);
'field' = 'persoon_voornaam' and 'rule' = 'required'
and validation.messages.persoon_voornaam.required works just fine.
What am i doing wrong?
validation is a JSON that look like this:
{
rules: {
persoon_voornaam: {
required: true,
minlength: 5,
},
postcode_bestemming: {
required: true,
minlength: 7,
},
},
messages: {
persoon_voornaam: {
required: 'Dit veld is verplicht',
minlengt: 'Dit veld moet minstens 5 lang zijn',
},
}
}