0

When hitting my sign-up page my jade template (with Twitter Bootstrap) is producing an empty error div (i.e. a red, opaque box with a closing link and no errors), despite the errors object returning typeof as 'undefined'. I've used this post for guidance on checking the value of errors. The code follows:

The controller:

/**
 * Show sign up form
 */
exports.signup = function(req, res) {
  res.render('users/signup', {
    title: 'Sign up',
    user: new User()
  });
};

The Jade template:

extends ../layouts/default

block content
  .row
    //-.offset1.span5
    .span6
      a(href="/auth/facebook")
        img(src="/img/icons/facebook.png")
      //- a(href="/auth/github")
        //- img(src="/img/icons/github.png")
      a(href="/auth/twitter")
        img(src="/img/icons/twitter.png")
      a(href="/auth/google")
        img(src="/img/icons/google.png")
    .span6
      if (typeof errors != 'undefined') // The following alert shouldn't be rendered
        .fade.in.alert.alert-block.alert-error
          a.close(data-dismiss="alert", href="javascript:void(0)") x
          ul
            each error in errors
              //- li= error.param
              li= error.msg

      block auth

I've tried the following, but get the same result every time:

if (typeof errors != 'undefined')
if (typeof errors !== 'undefined')
if (typeof errors != undefined)
if (typeof errors !== undefined)
if (null != errors)
if (null !== errors)
Community
  • 1
  • 1
CrankNPlank
  • 97
  • 2
  • 8

1 Answers1

0

EDIT: From what you said in the comments, errors is not undefined when there are no errors; instead, it is an empty array. This answer now checks for that instead.

It would help to see this working somewhere, but it's possible that changing your Jade code to this will solve it:

  - if (errors.length > 0) {// The following alert shouldn't be rendered
    .fade.in.alert.alert-block.alert-error
      a.close(data-dismiss="alert", href="javascript:void(0)") x
      ul
        each error in errors
          //- li= error.param
          li= error.msg
  - }
Evan
  • 825
  • 4
  • 14