hỏi về express validator
-
e có đoạn code dùng express validator
req.checkBody('title','Title is required !').notEmpty();
let errors = req.validationErrors();
if(errors){
res.render('add_category',{
errors : errors,
title : 'Create Category'
});
}
ở file add_category
<% if(errors){ %>
<% errors.forEach(function(error){ %>
<li class="alert alert-danger"><%=error.msg%></li>
<% }) %>
<% } %>
mà nó báo : errors is not defined
là sai sót chỗ nào ạ, mong ace support giùm e với -
@minhit
Theo những gì mình thấy thì
Hiện tại title đã validate
=> errors chắc là false(90%)
=> đoạn render của bạn đâu có chạy
=> tìm phía dưới xem có đoạn render nào rồi sét lại errors cho nó
Hy vọng là được
https://github.com/ctavan/express-validator/issues/368
https://github.com/ctavan/express-validator#usage