node.js - Nodejs and Jade rendered my submit button as a text field -
in nodejs application, jade templating, can't manage render submit button.
this app.js code :
var express = require('express'); var app = express(); app.get('/todo', function(req,res){ res.set({ "content-type" : "text/html", "charset" : "utf-8" }); res.render('todo_list.jade', {list : [ "lire un livre", "jouer de la musique", "apprendre la programmation", "jouer au dé pipé !" ]}); }); // app.post('/todo/ajouter', function(req, res){ // // }); // // app.post('/todo/supprimer/:id', function(req, res){ // // }); app.listen(8080);
this view/todo_list.jade :
doctype html head title ma todo list body h1 ma todo list ul - (var = 0; < list.length; i++) li #{list[i]} form label(for=new_task) que dois-je faire ? input(type=text, id=new_task, name=new_task, size=15) input(type=submit, value=ajouter)
so why getting 2 text fields instead of text field , button ?
in application root folder, i've installed (with package.json file) express ~4.3.2, cookie-session ~1.0.2, body ~4.4.2, , jade ~1.3.1
the cause of problem not assigning attributes tags. in jade, attribute values evaluated javascript expressions. means leaving attribute values unquoted use variable's value rather literal value.
here fixed jade template give desired output:
doctype html head title ma todo list body h1 ma todo list ul - (var = 0; < list.length; i++) li #{list[i]} form label(for='new_task') que dois-je faire ? input(type='text', id='new_task', name='new_task', size=15) input(type='submit', value='ajouter')
Comments
Post a Comment