Different behavior when using jade instead of EJS - javascript

In my node.js application, I've been using EJS as a template engine. But due to some limitations, I decided to switch to Jade.
In my homepage, I have a navbar produced by Bootstrap 3. Inside this navbar, I have a form with 2 buttons.
When I used EJS, these buttons were space-separated, exactly like in Bootstrap's navbar documentation :
But when I switched to Jade, the result was :
I tried with the code from Bootstrap's navbar documentation, and I got the same issue : no spaces with Jade. (http://getbootstrap.com/components/#navbar)
And my body contains 2 divs. With EJS, I had a space between them (I supposed it was some Bootstrap's magic), none with Jade
I checked all my files twice. They contain exactly the same CSS, the same markup.
I'm struggling with this issue. Can you help me ?
Thanks in advance.
EDIT: Here is the code, I took a very basic example from bootstrap's documentation
Jade
<!DOCTYPE html><html><head><title>Express</title><link rel="stylesheet" href="/stylesheets/style.css"><link rel="stylesheet" href="/js/bower_components/bootstrap/dist/css/bootstrap.min.css"><script src="/js/bower_components/bootstrap/dist/js/bootstrap.min.js"></script></head><body><nav role="navigation" class="navbar navbar-default"><div class="container-fluid"><div class="navbar-header"><button type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" class="navbar-toggle collapsed"><span class="sr-only">Activer la navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button></div><div id="bs-example-navbar-collapse-1" class="collapse navbar-collapse"><form id="uploadFileForm" role="send" enctype="multipart/form-data" class="navbar-form navbar-left"><div class="form-group"><input id="textFile" type="text" placeholder="Envoi de fichier" class="form-control"></div><button type="submit" class="btn btn-default">Envoi</button></form><p class="navbar-text navbar-right">Express</p></div></div></nav></body></html>
Template
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='stylesheet', href='/js/bower_components/bootstrap/dist/css/bootstrap.min.css')
script(src='/js/bower_components/bootstrap/dist/js/bootstrap.min.js')
body
nav.navbar.navbar-default(role='navigation')
div.container-fluid
div.navbar-header
button.navbar-toggle.collapsed(type='button', data-toggle='collapse', data-target='#bs-example-navbar-collapse-1')
span.sr-only Activer la navigation
span.icon-bar
span.icon-bar
span.icon-bar
div#bs-example-navbar-collapse-1.collapse.navbar-collapse
form#uploadFileForm.navbar-form.navbar-left(role='send', enctype='multipart/form-data')
div.form-group
input#textFile.form-control(type='text', placeholder='Envoi de fichier')
button.btn.btn-default(type='submit') Envoi
p.navbar-text.navbar-right= title
EJS
<!DOCTYPE html>
<html>
<head>
<title>Express</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<link rel='stylesheet' href='/js/bower_components/bootstrap/dist/css/bootstrap.min.css' />
<script src="/js/bower_components/bootstrap/dist/js/bootstrap.min.js" ></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Activer la navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form class="navbar-form navbar-left" role="send" enctype="multipart/form-data" id="uploadFileForm">
<div class="form-group">
<input type="text" id="textFile" class="form-control" placeholder="Envoi de fichier">
</div>
<button type="submit" class="btn btn-default">Envoi</button>
</form>
<p class="navbar-text navbar-right">Express</p>
</div>
</div>
</nav>
</body>
</html>
Template
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<link rel='stylesheet' href='/js/bower_components/bootstrap/dist/css/bootstrap.min.css' />
<script src="/js/bower_components/bootstrap/dist/js/bootstrap.min.js" ></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Activer la navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form class="navbar-form navbar-left" role="send" enctype="multipart/form-data" id="uploadFileForm">
<div class="form-group">
<input type="text" id="textFile" class="form-control" placeholder="Envoi de fichier">
</div>
<button type="submit" class="btn btn-default">Envoi</button>
</form>
<p class="navbar-text navbar-right"><%= title %></p>
</div>
</div>
</nav>
</body>
</html>
style.css
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}

Jade by default removes all spaces from html. That leads for boostrap to format buttons together.
Write buttons this way:
button.btn.btn-primary Button 1
= ' '
button.btn.btn-primary Button 2
= ' '
button.btn.btn-primary Button 3

Related

Toggle is not responding in small screen

I created a Navbar and added searchbar and login signup options however before adding them, code for toggle was working fine and it was responding on small screens but now it is not working.
can you help me to find out where I am making mistake....
I am using Bootstrap-5 here.
I am expecting toggler to respond on small screens which is not working right now.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0/dist/css/bootstrap.min.css">
<nav class="navbar navbar-expand-lg navbar-dark shadow-10-strong bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Travel <b> Friend </b> </a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collection of Nav Links , forms and other content for toggeling -->
<div class="collapse navbar-collapse justify-content-start" id="navbarNav">
<!-- There are two ways to add feature lists one was to use UL and LI and second was to just add A tag which was easy -->
<div class="navbar-nav">
Home
About
Pricing
Blog
Contact
</div>
<!-- for searchbar -->
<form class="navbar-form form-inline">
<div class="input-group search-box">
<input type="text" id="search" class="form-control bg-transparent" placeholder="Search here..." />
<div class="input-group-append">
<span class="input-group-text bg-transparent">

</span>
</div>
</div>
</form>
<!-- Form close here -->
<!-- Login and Sign Up icons here -->
<div class="navbar-nav ms-auto action-buttons">
Login
Sign up
</div>
</div>
</div>
</nav>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0/dist/js/bootstrap.min.js"></script>

Django JavaScript fpr bootstrap grid does not work

I deployed website using Django. I used external js code for grid (I want site to be user-friendly for all screens). When running just html using same js code or running it on my computer through manage.py it works fine. But when I actually deployed website grid become unclickable from small screens and you cannot see menu.
I couldn't find anything in Google. I am not sure if I have to use load static because I use external script, but tell me if I am wrong
<!DOCTYPE html>
{% load static %}
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<!-- DOCUMENTATION NAVBAR -->
<nav class="navbar navbar-default navbar-inverse navbar-fixed-top">
<!-- Inside of a Container -->
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<!-- This is the actual code that create the "hamburger icon" -->
<!-- The data-target grabs ids to put into the icon -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<!-- Code for the hamburger icon-->
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" style="color:white;"
href="{% url 'wpb:index' %}">
Mycroft Conspiracy Project</a>
</div>
<!-- Anything inside of collapse navbar-collapse goes into the "hamburger" -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">О проекте <span class="sr-only">(current)</span></li>
<li class="active">Политика<span class="sr-only">(current)</span></li>
<li class="active">Психология<span class="sr-only">(current)</span></li>
</ul>
<!-- SEARCH BAR -->
<form action="{% url 'wpb:search' %}" method="get" class="navbar-form navbar-right">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Поиск">
</div>
<button type="submit" class="btn btn-default" name="search">Поиск</button>
</form>
<!-- Stuff on the Right -->
<ul class="nav navbar-nav navbar-right">
<li>Обратная связь</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<!-- OTHER STUFF ON THE PAGE -->
<!-- Need to have JQuery and Javascript for DropDown Actions to work -->
<script
src="http://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script> <!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container">
<br />
<br />
<br />
<body style=" height: 800px;
position: relative;">
{% block body_block %}
{# Anything outside of this will be inherited if you use extend.#}
{% endblock %}
</body>
</div>
</br>
<div style="font-family:Palatino Linotype;position: sticky; position: -webkit-sticky;left:0;bottom:0;width:100%; top: 100%; height: 12rem;background-color:#2e2c27; border:1px dotted #003333; padding:.8em; ">
<h4 style="color:white;font-weight: bold;">Mycroft Conspiracy Project</h4>
<span style="font-size:12pt; font-family: 'Cambria','times new roman','garamond',serif; color:white;">Достоверность информации</span></br>
<p style="font-size:10pt; line-height:10pt; font-family: 'Cambria','times roman',serif; color: white;">Проект является любительским и не носит информационный характер. Хотя автор указывает в каждой статье степень своего личного отношения к
описываемым версиям или данным, здесь отсутствуют намерения представить статьи как источники, на которые стоит ссылаться. При копировании материалов с сайта ссылка
обязательна.</p>
<span style="padding-top:10px; font-weight:bold; color:#CC0000; font-size:10pt; font-family: 'Calibri',Arial,sans-serif; "></span></br></br>
</div>
</body>
</html>
Found it. Problem was that link to js code was starting with http. Browser was blocking it as mixed content. Needed just to change it to https.

when it is a must to use descendant selectors

The following code is a part of an html file which utilizes bootstrap. Mainly I want to style <a> which has a class .navbar-brand. To do so I added another class .grandchildlink to <a> (don't pay attention to the name). The problem is that it does not work this way.., the two alternatives were:
1. Using descendant selectors eg. by using the class .parentbody of <body> and then ( .parentbody .grandchildlink:hover, .parentbody .grandchildlink:focus{...})
2. Adding an id attribute to <a> say: grandchildlink_id and then (#grandchildlink_id:hover, #grandchildlink_id:focus {...})
.., the question is why isn't it working with a one class selector ?
.
.
.
<style type="text/css">
.grandchildlink:hover, .grandchildlink:focus {
background-color: transparent;
color: yellow;
}
</style>
</head>
<body class="parentbody">
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle naviagation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="grandchildlink navbar-brand" >BrandName</a>
<div class="navbar-collapse collapse">
<ul></ul>
</div>
</div>
</div>
.
.
.
Because of css specificity. This is the CSS bootstrap uses.
.navbar-inverse .navbar-brand:focus, .navbar-inverse .navbar-brand:hover {
color: #fff;
background-color: transparent;
}
That means to overwrite it, you need to use .navbar-inverse .grandchildlink {} or something with an equal (as long as your styles come after bootstrap.css) or higher specificity, like you listed in your examples.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.navbar-inverse .grandchildlink:hover, .navbar-inverse .grandchildlink:focus {
background-color: transparent;
color: yellow;
}
</style>
<body class="parentbody">
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle naviagation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
BrandName
<div class="navbar-collapse collapse">
<ul></ul>
</div>
</div>
</div>

TypeError: Cannot read property '0' of null

I'm working on a NodeJS Project that uses Sails.js as a framework.
What I'm trying to accomplish is a permissions system where the permissions per group are set by Check Boxes, I'm using a typical form with AngularJS.
When I click my "Sumbit" button it throws this error at my Browser's console:
angular.1.3.js:11594 TypeError: Cannot read property '0' of null
at $parseFunctionCall (angular.1.3.js:12333)
at callback (angular.1.3.js:22949)
at Scope.$eval (angular.1.3.js:14383)
at Scope.$apply (angular.1.3.js:14482)
at HTMLFormElement.<anonymous> (angular.1.3.js:22954)
at HTMLFormElement.eventHandler (angular.1.3.js:3011)(anonymous function) # angular.1.3.js:11594
Any help with this would be greatly appreciated.
EDIT Forgot the Code:
Here is the code that receives the information POSTed from the form
createGroup: function(req, res) {
Groups.create({
groupName: req.param('groupName'),
canViewUsers: req.param('canViewUsers'),
canEditUsers: req.param('canEditUsers'),
canPromoteToStaff: req.param('canPromoteToStaff'),
canViewNotes: req.param('canViewNotes'),
canEditPermissions: req.param('canEditPermissions')
});
Here is the code for that catches the information and POSTs it to the create function
angular.module('GroupsModule').controller('GroupsController', ['$scope', '$http', 'toastr', function($scope, $http, toastr) {
$scope.createGroup = {
loading: false
};
$scope.createGroupForm = function(){
// Set the loading state (i.e. show loading spinner)
$scope.createGroup.loading = true;
// Submit request to Sails.
$http.post('/createGroup', {
groupName: $scope.createGroupForm.groupName,
canViewUsers: $scope.createGroupForm.canViewUsers,
canEditUsers: $scope.createGroupForm.canEditUsers,
canPromoteToStaff: $scope.createGroupForm.canPromoteToStaff,
canViewNotes: $scope.createGroupForm.canViewNotes,
canEditPermissions: $scope.createGroupForm.canEditPermissions
})
.then(function onSuccess(sailsResponse){
window.location = '/groups';
})
.catch(function onError(sailsResponse){
// Handle known error type(s).
// If using sails-disk adpater -- Handle Duplicate Key
var groupAlreadyExists = sailsResponse.status == 409;
if (groupAlreadyExists) {
toastr.error('That group already exists', 'Error');
}
})
.finally(function eitherWay(){
$scope.createGroup.loading = false;
})
There are closing brackets but they aren't getting formatted correctly in the post.
And finally here is the code for the Form itself:
<!--STYLES-->
<link rel="stylesheet" href="/styles/angular-toastr.css">
<link rel="stylesheet" href="/styles/bootstrap.3.1.1.css">
<link rel="stylesheet" href="/styles/importer.css">
<link rel="stylesheet" href="/styles/style.css">
<link rel="stylesheet" href="/styles/theme.css">
<link rel="stylesheet" href="/styles/theme.min.css">
<!--STYLES END-->
<body ng-app="DashboardModule" ng-controller="DashboardController" ng-cloak>
<div class="bs-docs-section clearfix">
<div class="row">
<div class="bs-component">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Insomnia eSports</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><i class="fa fa-users" aria-hidden="true"></i> Group Management </li>
</ul>
<!--
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
-->
<ul class="nav navbar-nav navbar-right">
<li>Sign Out</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
</div>
<form ng-submit="createGroupForm()" id="create-group-form" class="form-signin" name="createGroupForm">
<h2 class="form-signin-heading">Create an account</h2>
<div class="row">
<!-- Group Name -->
<label>Group Name</label>
<input type="text" class="form-control" placeholder="Group Name" name="groupName" ng-model="createGroupForm.name" ng-maxlength="25" required>
</div>
<!-- Can View Users -->
<label>View Users?</label>
<input type="checkbox" name="canViewUsers" ng-model="canViewUsers.value">
<!-- Can View Users -->
<label>Edit Users?</label>
<input type="checkbox" name="canEditUsers" ng-model="canEditUsers.value">
<!-- Can Promote To Staff -->
<label>Promote to Staff?</label>
<input type="checkbox" name="canPromoteToStaff" ng-model="canPromoteToStaff.value">
<!-- Can Promote To Staff -->
<label>Can view notes?</label>
<input type="checkbox" name="canViewNotes" ng-model="canViewNotes.value">
<!-- Can Promote To Staff -->
<label>Can edit permissions?</label>
<input type="checkbox" name="canEditPermissions" ng-model="canEditPermissions.value">
<br/>
<!-- Disable signup button until the form has no errors -->
<button class="btn btn-success btn-lg btn-block" type="submit" ng-disabled="createGroupForm.$invalid">
<span ng-show="!createGroupForm.loading">Create Group</span>
<span class="overlord-loading-spinner fa fa-spinner" ng-show="createGroupForm.loading" ></span>
<span ng-show="createGroupForm.loading">Preparing your new group...</span>
</button>
<input type="hidden" name="_csrf" value="<%= _csrf %>" />
</form>
<!--SCRIPTS-->
<script src="/js/dependencies/sails.io.js"></script>
<script src="/js/dependencies/angular.1.3.js"></script>
<script src="/js/dependencies/Base64.js"></script>
<script src="/js/dependencies/angular-toastr.js"></script>
<script src="/js/dependencies/compareTo.module.js"></script>
<script src="/js/public/signup/SignupModule.js"></script>
<script src="/js/public/groups/GroupsModule.js"></script>
<script src="/js/private/dashboard/DashboardModule.js"></script>
<script src="/js/public/homepage/HomepageModule.js"></script>
<script src="/js/private/dashboard/DashboardController.js"></script>
<script src="/js/public/groups/GroupsController.js"></script>
<script src="/js/public/homepage/HomepageController.js"></script>
<script src="/js/public/signup/SignupController.js"></script>
<!--SCRIPTS END-->
</body>
This was solved by me incorrectly using $scope on createGroupForm instead of just createGroup. The corrected code bit is below:
Instead of:
$scope.createGroupForm.canViewUsers
Use:
$scope.createGroup.canViewUsers

Mobile Navbar won't show when clicked

When viewing at mobile screen resolution and you select the mobile nav icon bar, nothing happens. The desired effect is to have the same main navigation be used in mobile. I have ensured my data-targets (mobile_nav) match, and that markup looks good, but am new to Bootstrap. Any help appreciated!
<!DOCTYPE html>
<html>
<head>
<title>Homepage</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- Loading Fonts Awesome CDN from boostrapcdn.com -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<!-- add padding from best practices for fixed topbar navs -->
<header>
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mobile_nav" >
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Brand
</div>
<div class="collapse navbar-collapse" id="mobile_nav">
<ul class="nav navbar-nav">
<li>Link 1</li>
<li>Link 2</li>
</ul>
<form action="" class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</header>
</body>
</html>
Bootstrap requires jQuery to work, you should include it before the Bootstrap JS in your HTML:
<!-- JQuery -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Categories

Resources