Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    hỏi về express validator

    Hỏi Đáp
    0
    2
    696
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      minhit last edited by

      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

      Khoa Lê Duy 1 Reply Last reply Reply Quote 0
      • Khoa Lê Duy
        Khoa Lê Duy @minhit last edited by

        @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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post