Datepicker - invalid date & class style - datepicker

Following your sample code
<div class="col-6">
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control form-control-sm" placeholder="yyyy-mm-dd"
name="d2" #c2="ngModel" [(ngModel)]="model2" ngbDatepicker #d2="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-sm btn-outline-secondary dropdown-toggle" (click)="d2.toggle()" type="button">
</button>
</div>
</div>
</div>
</form>
<hr/>
<button class="btn btn-sm btn-outline-primary" (click)="model2 = null">Select Today</button>
<hr/>
<pre>M: {{ model2 | json }}</pre>
<pre>S: {{ c2.status }}</pre>
<pre>B: {{ c2.status==INVALID }}</pre>
</div>
works fine. But I want to set an error-class for the whole input-group, something like
<div class="input-group" [ngClass]="{ 'has-error':isInValid }">
But the evalutation of the c2.status never evaltuates to true/false dynamically. It remains unchanged ==> How to make a proper compare to set the class dynamically?

Thx to JB Nizet I figured out the following proper syntax:
<div class="input-group" [ngClass]="{ 'has-error': c2.invalid }">

Related

Angular error:Form submission canceled because the form is not connected

What I am trying to do is -
I am trying to add a form to the existing form but the data not getting stored
what the error coming up -
in the console its showing form connection is missing.. how can I connect it with following code I have?
The code behind the click is something like this:
<button type="submit" class="btn btn-default" routerLink="../viewemployee" [disabled]="empForm.invalid">Add Employee</button>
please refer the link below for the code.. need help to move on from this to solve other tasks.
If it is required to post the code here as well, I will do.Please answer and respond.
Thanx in advance.
How to connect the form in angular routing
createemployee.component.html
<h2>Add Employee:</h2>
<form class="form-horizontal" #empForm="ngForm">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" minlength="4" maxlength="10" pattern="^[A-Za-z0-9]*[A-Za-z0-9][A-Za-z0-9]\S*$" [(ngModel)]="model.name" placeholder="Enter Your Name"
#name="ngModel" required/>
<div *ngIf="name.invalid && (name.dirty || name.touched)" class="alert alert-danger">
<div *ngIf="name.errors.required">
Name is required.
</div>
<div *ngIf="name.errors.pattern">
No Spaces
</div>
<div *ngIf="name.errors.minlength">
Name must be at least 4 characters long.
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="position">Position:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="position" minlength="4" maxlength="10" pattern="^[a-z]*$" [(ngModel)]="model.position" placeholder="Enter your position"
#position="ngModel" required />
<div *ngIf="position.invalid && (position.dirty || position.touched)" class="alert alert-danger">
<div *ngIf="position.errors.required">
Position is required.
</div>
<div *ngIf="position.errors.pattern">
Only Alphabets are must be entered
</div>
<div *ngIf="position.errors.minlength">
Position must be at least 4 characters long.
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="salary">Salary:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="salary" pattern="[0-9]*"
minlength="5" maxlength="7" [(ngModel)]="model.salary" placeholder="Enter Salary" #salary="ngModel" required />
<div *ngIf="salary.invalid && (salary.dirty || salary.touched)" class="alert alert-danger">
<div *ngIf="salary.errors.required">
Salary is required.
</div>
<div *ngIf="salary.errors.minlength">
Salary must be in 5 numbers.
</div>
<div *ngIf="salary.errors.maxlength">
Salary must not be exceeded morethan 7 numbers.
</div>
<div *ngIf="salary.errors?.pattern">Only numebers should be typed
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" routerLink="../viewemployee" [disabled]="empForm.invalid">Add Employee</button>
<button type="button" class="btn btn-default" routerLink="../home">Cancel</button>
</div>
</div>
</form>
You could change your component as follows:
Add event handler to the form:
<form (ngSubmit)="continue()">
Handle the routing in code:
continue() {
...
this.router.navigateByUrl("../viewemployee");
}
You need to inject the router:
constructor(private router: Router) {}

Angular 4 Reset status form

I have a modal with a form, and some required fields.
When I open the modal I correctly see the fields empty, if I write something in the field required and then I cancel the words writed I correctly see the field as invalid.
The problem is that if I close and reopen the modal I want to see the empty fields like if it's the first time I open it but for some reason I see the previous invalid status also if I reset the form.
This is my modal after I close it, it seems that the status never be resetted:
<form #modelForm="ngForm">
<div class="modal-body" *ngIf="checkpoint">
<div class="row">
<div class="form-group label-floating">
<label class="control-label">{{'checkpoint.table.dialog.labels.name'
| translate }}<span class="star">*</span>
</label> <input class="form-control" id="name" name="name" required
[(ngModel)]="checkpoint.name" #name="ngModel" /><small
[hidden]="name.valid || name.pristine" class="text-danger">
{{'checkpoint.table.validations.required' | translate }}</small>
</div>
</div>
<div class="row">
<div class="form-group label-floating">
<label class="control-label">{{'checkpoint.table.dialog.labels.passStockAlert'
| translate }}</label> <input pattern="[0-9]*"
class="form-control" name="passStockAlert"
id="passStockAlert"
[(ngModel)]="checkpoint.passStockAlert"
#checkPoint="ngModel" /><small
[hidden]="checkPoint.valid || checkPoint.pristine"
class="text-danger">
{{'checkpoint.table.validations.invalid' | translate }}</small>
</div>
</div>
<div class="row">
<div class="category form-category">
<span class="star">*</span> {{ 'form.requiredfields' |
translate }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info btn-round"
(click)="save();resetForm(modelForm)" data-dismiss="modal"
[disabled]="modelForm.form.invalid || modelForm.form.pristine"
label="Save">{{'checkpoint.table.dialog.save' |
translate }}</button>
<button type="button" class="btn btn-danger btn-round"
(click)="resetForm(modelForm)" data-dismiss="modal">{{'checkpoint.table.dialog.close' |
translate }}</button>
</div>
</form>
And this is my reset form method:
resetForm(myForm: NgForm) {
myForm.form.reset();
}
I have successfully implemented this:
my-component.html
<form (ngSubmit)="resetFormFlags(myForm)" #myForm="ngForm">
<h4> title </h4>
<button type="submit"> btnText</button>
</form>
my-component.ts
resetFormFlags(myForm: any) {
myForm.reset();
}
Hope it helps!
Try like this below code :
<form name="modelForm" role="form" novalidate (ngSubmit)="resetForm(modelForm)" #modelForm="ngForm">
<div class="modal-body" *ngIf="checkpoint">
<div class="row">
<div class="form-group label-floating">
<label class="control-label">{{'checkpoint.table.dialog.labels.name'
| translate }}<span class="star">*</span>
</label>
<input class="form-control" id="name" name="name" required [(ngModel)]="checkpoint.name" />
<small [hidden]="!(modelForm.controls.name?.dirty && modelForm.controls.name?.invalid)" class="text-danger">
{{'checkpoint.table.validations.required' | translate }}
</small>
</div>
<button class="btn btn-primary" [disabled]="modelForm.form.invalid" type="submit">{{'checkpoint.table.dialog.save' | translate }}</button>
<button class="btn btn-white" type="button" (click)="resetForm(modelForm)"> {{'checkpoint.table.dialog.close' | translate }}</button>
</div>
</div>
</form>
componen.ts
resetForm(editForm: NgForm) {
editForm.reset();
}

Laravel. Button in FORM tag doesn't work like the others

The buttons inside my panel-body doesn't work. This is the code:
<div class="panel-body">
<table border="3">
<!-- <div id="tray"></div> -->
#forelse($carts as $cart)
<div class="row">
<div class="col-md-1">{{$cart->id}}</div>
<div class="col-md-3">{{$cart->name}}</div>
<div class="col-md-4">
<div class="row clearfix">
<div class="col-md-1">
<form action="/restaurant/minus" method="POST">
<input type="hidden" name="trayid" id="trayid" value="{{$cart->id}}">
<input type="hidden" name="trayprice" id="trayprice" value="{{$cart->price}}">
<button type="submit" class="btn btn-xs btn-primary" style="border-radius: 50%;" id="{{$menu->id}}"><i class="fa fa-minus" aria-hidden="true"></i></button>
</form>
</div>
<div class="col-md-4">
<input type="number" min="1" value="{{$cart->quantity}}" style="width:40px;">
</div>
<div class="col-md-1">
<form action="/restaurant/plus" method="post">
<input type="hidden" name="trayid" id="trayid" value="{{$cart->id}}">
<input type="hidden" name="trayprice" id="trayprice" value="{{$cart->price}}">
<button type="submit" class="btn btn-xs btn-primary" style="border-radius: 50%"><i class="fa fa-plus" aria-hidden="true"></i></button>
</form>
</div>
</div>
</div>
<div class="col-md-2">
<input type="hidden" name="trayprice" value="{{$cart->price}}">
</div>
<div class="col-md-1">
<form action="/restaurant/delete" method="post">
<input type="text" name="deleteid" id="deleteid" value="{{$cart->id}}">
<button type="submit" class="btn btn-xs btn-danger" style="border-radius: 50%;"><i class="fa fa-trash" aria-hidden="true"></i></button>
</form>
</div>
</div>
#empty
#endforelse
</table>
</div>
Meanwhile, the button in my panel-header works, and it just clears the body.
<div class="panel-heading">
<div class="row clearix">
<form class="col-md-12" method="POST" action="/restaurant/cleartray">
{{ csrf_field() }}
<p class="pull-left">Tray</p>
<button type="submit" class="btn btn-danger btn-xs pull-right"><i class="fa fa-eraser" aria-hidden="true"></i> Clear</button>
</form>
</div>
</div>
Is there anything wrong with the structure that made it impossible for the button to work?
P.S: It doesn't even gets to the route target. It doesn't refresh or something like that. It's like the button itself is unresponsive.
EDIT: I found out that the buttons in the form doesn't work once it's inside the forelse loop.
I think you can change your route action like:
<form action="/restaurant/plus" method="post">
TO
<form action="{{ url('restaurant/plus') }}" method="post">
Hope this work for you!
I kinda got the answer by literally debugging it, haha.
It turns out that having a form tag inside the table tag isn't going to go well. So I took out the table tag. (Didn't remember why I had it in the first place)
Aaaaand voila! It worked!

Checkbox and caption without line break

I can't place checkbox and "Remember me" in one line using laravel and bootstrap. There is a line break between checkbox and "Remember me" but I don't want that line break.
My code:
{{Form::open(['route'=>'sessions.store','class'=>'form-horizontal'])}}
<div class = 'form-group'>
{{Form::label('email','Email',['class'=>'col-sm-3 control-label'])}}
<div class="col-sm-4">
{{Form::email('email',null,['class'=>'form-control'])}}
{{$errors->first('email')}}
</div>
</div>
<div class = 'form-group'>
{{Form::label('password','Password',['class'=>'col-sm-3 control-label'])}}
<div class="col-sm-4">
{{Form::password('password',['class'=>'form-control'])}}
{{$errors->first('password')}}
</div>
</div>
<div class = 'form-group'>
<div class='col-sm-offset-3 col-sm-4'>
{{Form::checkbox('remember-me',1,null,['class'=>'checkbox'])}}
{{Form::label('remember-me','Remember me')}}
</div>
</div>
<div class = 'form-group'>
<div class="col-sm-offset-3 col-sm-4">
{{Form::submit('Login',['class'=>'btn btn-default'])}}
</div>
</div>
{{Form::close()}}
That's because you're generating this markup for the 'Remember me' checkbox:
<div class="form-group">
<div class="col-sm-offset-3 col-sm-4">
<input class="checkbox" name="remember-me" type="checkbox" value="1">
<label for="remember-me">Remember me</label>
</div>
</div>
While this is the expected markup for the default Twitter Bootstrap checkbox:
<div class="checkbox">
<div class="col-sm-offset-3 col-sm-4">
<label>
<input type="checkbox" name="remember-me" value="1"> Remember me
</label>
</div>
</div>
To fix this, you can use this Blade excerpt in your view:
<div class="checkbox">
<div class="col-sm-offset-3 col-sm-4">
<label>
{{ Form::checkbox('remember-me', 1) }}
</label>
</div>
</div>

Bootstrap dropdown form width using col-*

I am trying to make dropdown login form in navigation bar using Bootstrap 3, but it does not look good - labels and inputs are wider than drop down ... panel.
How I can change drop down form width using col-* Bootstrap classes?
Here is the code (http://getbootstrap.com/css/#forms-horizontal):
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Sign in <b class="caret"></b>
<div class="dropdown-menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-10">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
</div>
</li>
</ul>
Thanks in advance.
You could add padding to the .dropdown-menu and change your columns to col-lg-11
Example: http://bootply.com/110118