Scott
Scott

Reputation: 1342

How do I format jade forms?

I'm trying to refactor my app to use jade instead of ejs but am running into some problems setting up a login form.

Here's my original form in ejs:

<% if (message) { %>
<p><%= message %></p>
<% } %>

<form class="form-horizontal" action='/login' method="POST" id="loginForm">
  <fieldset>
    <div id="legend">
      <legend class="">Login</legend>
    </div>
    <div class="control-group">
      <!-- Username -->
      <label class="control-label"  for="username">Username</label>
      <div class="controls">
        <input type="text" id="username" name="username" placeholder="" class="input-xlarge">
      </div>
    </div>

    <div class="control-group">
      <!-- Password-->
      <label class="control-label" for="password">Password</label>
      <div class="controls">
        <input type="password" id="password" name="password" placeholder="" class="input-xlarge">
      </div>
    </div>

    <div class="control-group">
      <!-- session-->
      <label class="control-label" for="rememberme">Remember Me</label>
      <div class="controls">
        <input type="checkbox" name="rememberme"/>
      </div>
    </div>


    <div class="control-group">
      <!-- Button -->
      <div class="controls">
        <button class="btn btn-success">Login</button>
      </div>
    </div>
  </fieldset>
</form>

And here's my new form in jade:

extends layout

block content
    if message
        p= message
    form(class='form-horizontal',action='/login',method='POST',id='loginForm')
        fieldset
            div#legand
                legend Login
            div.control-group
                label(for='username',class='control-label') Username
                div.controls
                    input(type='text',id='username',name='username',placeholder='Username',class='input-xlarge')
            div.control-group
                label(for='password',class='control-label') Password
                div.controls
                    input(type='text',id='password',name='password',placeholder='Password',class='input-xlarge')
            div.control-group
                label(for='rememberme',class='control-label') Remember Me
                div.controls
                    input(type='checkbox',name='rememberme')
            div.control-group
                div.controls
                    input(type='submit',class='btn btn-success') Login

Codekit is throwing an error:

/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/runtime.js:173
  throw err;
        ^
Error: /Users/sm/Documents/Projects/Web_Applications/App/app/views/login.jade:27
    25| 
    26| 
  > 27|   

Invalid indentation, you can use tabs or spaces but not both
    at Object.Lexer.indent (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:672:15)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:770:15)
    at Object.Lexer.blank (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:179:19)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:744:15)
    at Object.Lexer.blank (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:179:19)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:744:15)
    at Object.Lexer.lookahead (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:106:46)
    at Object.Parser.lookahead (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:115:23)
    at Object.Parser.peek (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:92:17)
    at Object.Parser.tag (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:666:30)

How can I get past this indentation error and get this form to work? I'm only using tabs and no spaces so I don't understand what the problem is.

Upvotes: 2

Views: 10128

Answers (2)

shoebox
shoebox

Reputation: 147

I think your problem may be how you're specifying the button. Instead of:

            div.control-group
                div.controls
                    input(type='submit',class='btn btn-success') Login

Try:

            div.control-group
                div.controls
                    button(type='submit',class='btn btn-success') Login

Upvotes: 1

robertklep
robertklep

Reputation: 203534

This is probably caused by a space in the trailing empty lines in your Jade template (which you don't post, but are there according to the error message).

Upvotes: 2

Related Questions