Upgrade angular-messages affect my layout - css

Here is the screenshot of my login form:
But after I upgrade angular-message to version 1.4 and above, the layout changes to:
My source code:
<ion-view view-title="Login">
<ion-header-bar class="bar-calm">
<h1 class="title">Login</h1>
</ion-header-bar>
<ion-content class="padding">
<form name="signinForm" novalidate="">
<div style="line-height: 250px; background-color: rgb(255, 255, 255); border: 1px solid rgb(238, 238, 238); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-align: center; width: 100%; height: auto;">
<i class="icon ion-image" style="font-size: 64px; color: rgb(136, 136, 136); vertical-align: middle;"></i>
</div>
<div class="list">
<label class="item item-input"
ng-class="{'has-error' : signinForm.email.$invalid && signinForm.email.$dirty,
'valid-lr' : signinForm.email.$valid && signinForm.email.$dirty}">
<span class="input-label">Email</span>
<input type="email"
name="email"
placeholder="Email"
ng-model="data.email"
required>
</label>
<div class="form-errors"
ng-show="signinForm.email.$error && signinForm.email.$dirty"
ng-messages="signinForm.email.$error"
ng-messages-include="templates/form-errors.html">
</div>
<label class="item item-input"
ng-class="{'has-error-lr' : signinForm.password.$invalid && signinForm.$submitted, 'valid-lr' : signinForm.password.$valid && signinForm.$submitted}">
<span class="input-label">Password</span>
<input type="password"
name="password"
placeholder="Password"
ng-model="data.password"
ng-minlength="5">
</label>
<div class="form-errors"
ng-show="signinForm.password.$error && signinForm.password.$dirty"
ng-messages="signinForm.password.$error"
ng-messages-include="templates/form-errors.html">
</div>
</div>
<div class="spacer" style="height: 0px;"></div>
<button class="button button-calm button-block icon-left ion-android-social-user" ng-click="login()" ng-disabled="signinForm.$invalid">Login</button>
Not a memeber? Create an account
</form>
</ion-content>
</ion-view>
What could be the cause? Can anybody advise? Thanks.

If the ng-message directive is nested within the ng-messages directive, this should work. Otherwise, it is not guaranteed to work on the same element. The version makes no difference after Angular 1.2.18+. For example:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-messages.js"></script>
<script>
angular.module('foo', ['ngMessages']);
</script>
<script>
function bop(model, view)
{
var i = 0, len = 100000, buz = "";
for (i; i < len; i++)
{
buz = buz.concat(i);
}
bop.cache.put('listContent', buz);
view.loaded = true;
return model;
}
function baz($templateCache)
{
bop.cache = $templateCache;
return bop;
}
baz.$inject = ['$templateCache','$rootScope'];
angular.module('foo').filter('baz', baz);
</script>
<div ng-app="foo">
<form name="myForm">
<label>Check Me<input type="checkbox" ng-model="$root['required']"></label>
<div ng-include="'listContent' | baz:myForm"></div>
<div ng-messages="$root" style="color:green" role="alert">
<div ng-message="required">👯</div>
</div>
<div ng-messages="myForm">
<div ng-message="loaded" style="color:blue">Loaded</div>
</div>
</div>
compared to:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-messages.js"></script>
<script>
angular.module('foo', ['ngMessages']);
</script>
<script>
function bop(model, view)
{
var i = 0, len = 100000, buz = "";
for (i; i < len; i++)
{
buz = buz.concat(i);
}
bop.cache.put('listContent', buz);
view.loaded = true;
return model;
}
function baz($templateCache)
{
bop.cache = $templateCache;
return bop;
}
baz.$inject = ['$templateCache','$rootScope'];
angular.module('foo').filter('baz', baz);
</script>
<div ng-app="foo">
<form name="myForm">
<label>Check Me<input type="checkbox" ng-model="$root['required']"></label>
<div ng-include="'listContent' | baz:myForm"></div>
<div ng-messages="$root" style="color:green" role="alert">
<div ng-message="required">👯</div>
</div>
<div ng-messages="myForm">
<div ng-message="loaded" style="color:blue">Loaded</div>
</div>
</div>
References
ionic Issue #6040: Please provide option to validate form elements like <ion-input>, <ion-select>, <ion-textarea>
AngularJS Repo: ngmessage Issues

Related

Form input-field is too small using Materialize-CSS

I have a Login form for a basic Admin Portal, however the input-field itself to click on is extremely small. The bar itself seems to be the entire size of the clickable input-field, so you can't click the label whatsoever to enter.
Code as follows:
<div className="container">
<form onSubmit={handleSubmit} className="white">
<h5 className="center">Cars4U Administration</h5>
<div className="input-field">
<input type="text" name="username" className="validate" required onChange={handleChange} />
<label htmlFor="username">Username</label>
</div>
<div className="input-field">
<input type="password" name="password" className="validate" required onChange={handleChange} />
<label htmlFor="password">Password</label>
</div>
<div className="input-field center">
<button className='btn z-depth-0' type='submit'>Login</button>
</div>
</form>
</div>
If my cursor is in the following position, I am unable to click the input-field. I am only able to click it directly on the line:
CSS:
form {
background-color: white;
margin-top: 80px;
margin-left: 350px;
margin-right: 350px;
border-radius: 3px;
}
form label {
padding-left: 40px;
padding-right: 40px;
padding-top: 20px;
font-weight: 700;
}
form .input-field {
padding-left: 40px;
padding-right: 40px;
padding-top: 20px;
}
According to Anthony's suggestion, you're supposed to have both name and id as identifiers.
Add id to your input -
<input name="username"/> to <input name="username"id="username"/>
class App extends React.Component {
render() {
return (
<div className="container">
<form className="white">
<h5 className="center">Cars4U Administration</h5>
<div className="row">
<div className="input-field">
<input type="text" id="username" className="validate" required />
<label htmlFor="username">Username</label>
</div>
<div className="input-field">
<input
type="password"
id="password"
className="validate"
required
/>
<label htmlFor="password">Password</label>
</div>
</div>
<div className="input-field center">
<button className="btn z-depth-0" type="submit">
Login
</button>
</div>
</form>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("root"));
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="root"></div>

Bootstrap 4: validation breaks styling on inline form elements?

I am trying to validate an inline form field, with Bootstrap 4.
When validation is triggered, the inline form field jumps in width. Here is a fiddle (just click Enter without entering a value, to see the problem): https://jsfiddle.net/aq9Laaew/213418/
How can I fix this?
This is my HTML:
<form class="form-inline needs-validation" id="form-stage1" novalidate>
<label class="sr-only" for="stage1-amount">Amount in thousands</label>
<div class="input-group mb-1 mr-sm-1">
<div class="input-group-prepend"><div class="input-group-text">£</div></div>
<input type="number" step="5000" min="0" class="form-control" id="stage1-amount" required>
<div class="invalid-feedback">Please enter an amount to proceed</div>
</div>
<button type="submit" class="btn btn-secondary mb-1">Enter</button>
</div>
</form>
And this is my JavaScript:
d3.select('#form-stage1').on('submit', function(e) {
d3.event.preventDefault();
d3.event.stopPropagation();
d3.select(this).attr('class', 'was-validated');
});
Try this :
var form = document.getElementById('form-stage1');
d3.select('#form-stage1').on('submit', function(e) {
d3.event.preventDefault();
d3.event.stopPropagation();
d3.select(this).attr('class', 'form-inline was-validated');
$(".invalid-feedback").show();
if (form.checkValidity() !== false) {
d3.select('#stage1-results').style('display', 'inline-block');
var val = d3.select('#stage1-amount').property("value");
d3.select('#stage1-output').text(formatPounds(val));
var percentile = getPercentile('property', val)
d3.select('#stage1-lower').text(percentile);
d3.select('#stage1-higher').text(100-percentile-1);
}
});
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.form-control{
width:auto!important;
flex:0!important;
}
.input-group{
width:auto!important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container">
<form class="form-inline needs-validation" id="form-stage1" novalidate>
<label class="sr-only" for="stage1-amount">Amount in thousands</label>
<div class="input-group mb-1 mr-sm-1">
<div class="input-group-prepend"><div class="input-group-text">£</div></div>
<input type="number" step="5000" min="0" class="form-control" id="stage1-amount" required>
</div>
<button type="submit" class="btn btn-secondary mb-1">Enter</button>
<div class="invalid-feedback">Please enter an amount to proceed</div>
</div>
</form>
</div>
https://jsfiddle.net/aq9Laaew/215767/

change icon on click using css or ngClass only

Hy guys, I was trying to change icon on click, but I found only examples with jquery. I was wondering if it's possible using only css or ngClass since I'm working in an Angular project. I'm using font-awesome 5 and Bootstrap 4. Below is the code that I wrote in trying to achieve my goal.
HTML:
<div class="form-group row">
<div class="input-group">
<label for="password" class="col-md-3 col-form-label">Password</label>
<input type="password" name="password" id="password" #password1 class="col-md-9 form-control" placeholder="Password" [(ngModel)]="password">
<div class="input-group-append" (click)="changeType(password1, 1)">
<span class="input-group-text" [ngClass]="toggle1 ? 'fas fa-eye' : 'fas fa-eye-slash'"></span>
</div>
</div>
</div>
<div class="form-group row">
<div class="input-group">
<label for="c_password" class="col-md-3 col-form-label">Password Confirmation</label>
<input type="password" name="c_password" id="c_password" #password2 class="col-md-9 form-control" placeholder="Repeat Password" [(ngModel)]="c_password">
<div class="input-group-append" (click)="changeType(password2, 2)">
<span class="input-group-text" [ngClass]="toggle2 ? 'fas fa-eye' : 'fas fa-eye-slash'"></span>
</div>
</div>
</div>
component.ts:
toggle1: boolean = false;
toggle2: boolean = false;
changeType(password, num){
if(password.type=="password")
password.type = "text";
else
password.type = "password";
if(num == 1)
this.toggle1 = !this.toggle1;
else
this.toggle2 = !this.toggle2;
}
What I would like to achieve is to change the icon on the click and change the type of parameter passed to the function to show the password just written.
Here is the working example
https://stackblitz.com/edit/angular-5pmn3r?file=app%2Fapp.component.html
UPDATE
Use in this way,
<span class="input-group-text"><i [ngClass]="toggle2 ? 'fa fa-eye' : 'fa fa-eye-slash'"></i></span>
I am providing you just a sample with using css. hope it'll help you.
html
<input type="checkbox" />
css
input[type="checkbox"] {
width: 0;
height: 0;
margin: 0;
border: 0 none;
padding: 0;
}
input[type="checkbox"]:before {
content: url('http://placekitten.com/200/210');
display: block;
width: 200px;
height: 200px;
overflow: hidden;
}
input[type="checkbox"]:checked:before {
content: url('http://placekitten.com/210/220');
}

Vertical align in Materialize CSS

I'm trying to center a form on the screen using Materialize. I tried everything, but I can not do it for all resolutions and also be responsive. In certain resolutions it works perfect, but when you add or remove controls (), in some resolutions it looks good, in others it goes wrong. Some help? Thank you!
Code
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.1/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
.card {
margin: 1rem 0 1rem 0 !important;
}
.card .card-title {
background-color: #26a69a;
}
.card-title span {
display: block;
text-align: center;
padding: 5px;
}
.card-content {
padding: 30px;
}
.valign {
width: 100%;
}
.valign-wrapper {
width: 100%;
background: url("http://vunature.com/wp-content/uploads/2016/10/trees-woods-tree-nature-path-forest-landscape-amazing-pictures-of-wallpapers.jpg") no-repeat;
}
.circle {
display: block;
margin: 10px auto;
}
</style>
</head>
<body>
<header class="navbar-fixed">
<nav class="top-nav">
<div class="nav-wrapper grey darken-3">
<a class="brand-logo center" href="#">Logo</a>
<ul class="right">
<li>
Register
</li>
<li>
Log in
</li>
</ul>
</div>
</nav>
</header>
<div class="valign-wrapper">
<div class="valign">
<div class="container">
<div class="card">
<div class="card-title white-text">
<span>Register</span>
</div>
<div class="card-content">
<p>
Text text text text text text text text text text text text text text text text text text text text text text text
</p>
<form action="#" enctype="multipart/form-data" id="externalRegisterForm" method="post" novalidate="novalidate">
<div class="validation-summary-valid text-danger" data-valmsg-summary="true">
<ul>
<li style="display:none" />
</ul>
</div>
<div>
<section style="position: absolute; left: 50%; transform: translateX(-50%); display: none;">
<input type="submit" class="btn" value="Sign In">
<input type="submit" class="btn" value="x">
</section>
<img class="circle" src="https://images.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png" width="128" height="128" alt="">
</div>
<div class="row">
<div class="input-field col s12 m4 l4 xl4">
<input class="validate" data-val="true" data-val-required="El campo Nombre de usuario es obligatorio." id="UserName" name="UserName" type="text" />
<label for="UserName" class="active">Username</label>
</div>
<div class="input-field col s12 m4 l4 xl4">
<input class="validate" data-val="true" data-val-required="El campo Nombre(s) es obligatorio." id="Name" name="Name" type="text" />
<label for="Name" class="active">Name</label>
</div>
<div class="input-field col s12 m4 l4 xl4">
<input class="validate" data-val="true" data-val-required="El campo Apellido(s) es obligatorio." id="LastName" name="LastName" type="text" />
<label for="LastName" class="active">Last name</label>
</div>
<div class="input-field col s12">
<input class="validate" data-val="true" data-val-required="El campo Email es obligatorio." id="Email" name="Email" type="text" />
<label for="Email" class="active">Email</label>
</div>
</div>
</form>
</div>
<div class="card-action">
<input type="submit" class="btn" value="Sign In" form="externalRegisterForm" />
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.1/js/materialize.min.js"></script>
<script type="text/javascript">
$(function() {
$('.button-collapse').sideNav();
});
</script>
</body>
</html>
EDIT
https://image.ibb.co/h7ESBk/1.jpg
See the white line below. It is a resolution of 1366x768. If you add more input, it looks "normal" and responsive. But if you delete an input you can see how the white background is larger.
Based on the feedback you gave in the comments, I think all you need is to add min-height: calc(100vh - 64px); to .valign-wrapper.
That will fill the whole page. You may have to modify the background property as well to make sure the image fills up the whole element, I couldn't load the image so I couldn't test that. The vertical alignment is already working.
Before:
After:
These UI libraries have been offering a 'grid' solution to this for some time now. However, I find vanilla CSS flexbox (whether hard coded or scripted with JS in the browser) to be super easy for centering both ways.
As for breakpoints, you will need them. I went thru all this on this here project https://github.com/rhroyston/firebase-v4-auth. Feel free to copy& paste as you need. Snippet below.
//ON LOAD INITIALLY ASSUME PHONE
var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
doc.getElementById("title").style.display = "flex";
doc.getElementById("title-right").style.display = "none";
if (width >= 840) {
//IT'S A DESKTOP
doc.getElementById("title").style.display = "none";
doc.getElementById("title-right").style.display = "flex";
}
else if (width >= 480) {
//IT'S A TABLET
doc.getElementById("title").style.display = "flex";
doc.getElementById("title-right").style.display = "none";
}
//ON RESIZE INITIALLY ASSUME PHONE
window.addEventListener("resize", resizeThrottler, false);
var resizeTimeout;
function actualResizeHandler() {
// assuming device is a phone
doc.getElementById("title").style.display = "flex";
doc.getElementById("title-right").style.display = "none";
if (window.innerWidth >= 840) {
//device is a desktop
doc.getElementById("title").style.display = "none";
doc.getElementById("title-right").style.display = "flex";
}
else if (window.innerWidth >= 480) {
//device is a tablet
doc.getElementById("title").style.display = "none";
doc.getElementById("title-right").style.display = "flex";
}
}
function resizeThrottler() {
// ignore resize events as long as an actualResizeHandler execution is in the queue
if (!resizeTimeout) {
resizeTimeout = setTimeout(function() {
resizeTimeout = null;
actualResizeHandler();
// The actualResizeHandler will execute at a rate of 15fps
}, 66);
}
}

Background of fixed position div extends beyond edge of pop-up

I've created a scrollable pop-up that uses a jQuery plugin to hold the buttons in place at the top of the window as a user scrolls. This works except for one small problem...the white background that I have placed on the div containing the buttons (in order to prevent seeing the content scrolling beneath the buttons) is extending beyond the right edge of the pop-up. I've tried this in both Chrome and Firefox and they both do the same thing. Is there a CSS solution to this problem?
Here's my fiddle - http://jsfiddle.net/donnapep/NhmvH/2/
HTML
<div class="overlay"></div>
<div class="wrapper container modal-content">
<div>
<h1>Weather Settings</h1>
<div class="sticky-wrapper">
<div class="btn-toolbar sticky-buttons">
<button id="save" class="btn btn-primary" type="button">Save</button>
<button id="cancel" class="btn btn-primary" type="button">Cancel</button>
<button id="help" class="btn btn-primary" type="button">Help</button>
</div>
</div>
</div>
<form role="form">
<div class="row">
<div class="col-md-7">
<div class="form-group">
<label for="layout">Layout</label>
<div class="radio">
<input type="radio" name="layout" value="current" data-url="http://s3.amazonaws.com/Widget-Weather-Test/current.html" checked="checked">
<img src="http://s3.amazonaws.com/Widget-Weather-Test/images/thumbs/current-vertical.png" class="img-thumbnail">
<img src="http://s3.amazonaws.com/Widget-Weather-Test/images/thumbs/current-horizontal.png" class="img-thumbnail">
</div>
<div class="radio">
<input type="radio" name="layout" value="three-day" data-url="http://s3.amazonaws.com/Widget-Weather-Test/three-day.html">
<img src="http://s3.amazonaws.com/Widget-Weather-Test/images/thumbs/three-day-vertical.png" class="img-thumbnail">
<img src="http://s3.amazonaws.com/Widget-Weather-Test/images/thumbs/three-day-horizontal.png" class="img-thumbnail">
</div>
<div class="radio">
<input type="radio" name="layout" value="current-and-three-day" data-url="http://s3.amazonaws.com/Widget-Weather-Test/current-and-three-day.html" checked="checked">
<img src="http://s3.amazonaws.com/Widget-Weather-Test/images/thumbs/current-and-three-day-vertical.png" class="img-thumbnail">
<img src="http://s3.amazonaws.com/Widget-Weather-Test/images/thumbs/current-and-three-day-horizontal.png" class="img-thumbnail">
</div>
</div>
</div>
</div>
</form>
CSS
.overlay {
position: absolute;
z-index: 1;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.7);
}
.wrapper {
z-index: 2;
width: 90%;
height: 500px;
margin: 20px auto 0;
overflow: auto;
}
.sticky-buttons {
z-index: 10;
width: 100%;
padding-top: 20px;
padding-bottom: 20px;
background-color: #fff;
}
Javascript
$(document).ready(function () {
$(".sticky-buttons").sticky({
container: $(".wrapper"),
topSpacing: 21
});
});
Thx.
http://jsfiddle.net/4eAeA/
Looking at the docs for that plugin you can use getWidthFrom as an option argument.
$(document).ready(function () {
$(".sticky-buttons").sticky({
container: $(".wrapper"),
topSpacing: 21,
getWidthFrom : $(".wrapper")
});
});
#donnapep, a downside I saw from that plugin is that it does not keep the width in check on resize.
You will also need something like this :
var _stickybuttons = $(".sticky-buttons");
$(window).resize(function () {
_stickybuttons.sticky('update');
});
I changed your jquery to:
$(document).ready(function () {
$(".sticky-wrapper").sticky({
container: $(".wrapper"),
topSpacing: 21
});
});
Some position:absolute; to
.wrapper.container.modal-content
so that it does not extend to the right
and
width:100%;
z-index:20;
in .sticky-wrapper
Fiddle:
http://jsfiddle.net/NhmvH/9/
It moves to left now but you get the idea.
Dont know if by changing your plugin its easier but anyway I hope it helps a bit.

Resources