Can not access ng-model values inside controller [angularJS] - angularjs

When I try to access user.firstname value in controller, it gives the following error.
TypeError: Cannot read property 'firstname' of undefined
$scope.signUpCustomer = function(){
console.log("GGGGGGGGGGGGGGGGGGGGGGGGG ", $scope.user.firstname);
}
<form class="form-horizontal font-hp-simplified signUpUserForm row" role="form" ng-submit="signUpCustomer()" name ="signUpUserForm" ng-show="!userVendor">
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label for="firstname" class="col-md-12">First Name:</label>
<div class="col-md-12">
<input ng-model="user.firstname" type="text" class="form-control" name="firstname" required />
<span class="text-danger" ng-show="signUpUserForm.firstname.$invalid && signUpUserForm.firstname.$dirty ">First name is required</span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="lastname" class="col-md-12">Last Name:</label>
<div class="col-md-12">
<input ng-model="user.lastname" type="text" class="form-control" name="lastname" required />
<span class="text-danger" ng-show="signUpUserForm.lastname.$invalid && signUpUserForm.lastname.$dirty ">Last name is required</span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label for="email" class="col-md-12">Email:</label>
<div class="col-md-12">
<input ng-model="user.email" type="email" class="form-control" name="email" required />
<span class="text-danger" ng-show="signUpUserForm.email.$error.required && signUpUserForm.email.$dirty ">Email is required</span>
<span class="text-danger" ng-show="signUpUserForm.email.$error.email && signUpUserForm.email.$dirty ">Please enter valid email</span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="password" class="col-md-12">Password:</label>
<div class="col-md-12">
<input ng-model="user.password" type="password" class="form-control" name="password" required />
<span class="text-danger" ng-show="signUpUserForm.password.$invalid && signUpUserForm.password.$dirty">Password is required</span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label for="phone" class="col-md-12">Phone:</label>
<div class="col-md-12">
<input ng-model="user.phone" type="text" class="form-control" name="phone" required />
<span class="text-danger" ng-show="signUpUserForm.phone.$invalid && signUpUserForm.phone.$dirty">Phone is required</span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="country" class="col-md-12">Country:</label>
<div class="col-md-12">
<select name="country" ng-model="user.country" type="text" class="form-control form-bg-white" required>
<!-- <option value="" disabled selected>Select Your Country</option> -->
<option value="" disabled selected></option>
<option ng-repeat="country in countries" value="{{country}}">{{country}}</option>
</select>
<span class="text-danger" ng-show="signUpUserForm.country.$invalid && signUpUserForm.country.$dirty">Country is required</span>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-12">
<!-- Button -->
<div class="form-group">
<div class="col-md-12">
<div class="icon-user-signup">
<div class="input-group-addon">
<i class="fa fa-user"></i>
</div>
<button id="btn-signup" class="btn btn-primary col-md-12">SIGN UP</button>
</div>
</div>
<!-- <div class="mrg-top-10 col-md-12 text-right">
<h4><a ng-click="go('/seller#/signup')" class="ven-link">
Become a vendor today
</a></h4>
</div>-->
</div>
</div>
</div>
<!-- <div class="col-md-12 control">
<div class="signup-border" >
Already have an account ?
<a ui-sref="loginUser" >
Sign In Here
</a>
</div>
</div> -->
</form>

You need to initialize the $scope.customer first in controller
$scope.user = {};

Related

Need help in implementing look up functionality using angular with spring boot

I am new to angular JS and I have a requirement where I need to implement the look up functionality on modal-pop up dialog box.It is similar to finding bank branch using IFSC code lookup.I should be able to serach for a bank using bank name or IFSC code or branch name and then select the bank branch.Please assist.Any demo videos implementing this functionality will help me.
I do have a working code for modal pop-up.But am unable to proceed further.Please let me know if I have to share the code of what has been done so far.
Thanks,
Prashanth
Here is my html code
<div class="container" xmlns="http://www.w3.org/1999/html">
<div class="offset-3"></div>
<form name="form" #f="ngForm" (ngSubmit)="f.form.valid && saveData()" novalidate class="feedback-form">
<div class="row">
<div class="col">
<label for="accession">Accession</label>
<input type="text"
id="accession"
class="form-control"
name="accession"
[(ngModel)]="model.accession"/>
</div>
<div class="col">
<label for="template">Template</label>
<input type="text"
id="template"
class="form-control"
name="template"
[(ngModel)]="model.template"/>
</div>
<div class="col">
<label for="user">User</label>
<input type="text"
id="user"
class="form-control"
name="user"
[(ngModel)]="model.user"/>
</div>
<div class="col">
<label for="count">Count</label>
<input type="text"
id="count"
class="form-control"
name="count"
[(ngModel)]="model.count"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="firstName">First Name</label>
<input type="text"
id="firstName"
class="form-control"
name="firstName"
placeholder="Your firstName" [(ngModel)]="model.firstName"
#firstname="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && firstname.invalid }"
required maxlength="40"/>
<div *ngIf="f.submitted && firstname.invalid" class="invalid-input">
<div *ngIf="firstname.errors?.required">
First Name is required
</div>
<div *ngIf="firstname.errors?.maxlength">
First Name can have a maximum of 40 characters
</div>
</div>
</div>
<div class="col">
<label for="doctorNumber">Doctor Number</label>
<input type="text"
id="doctorNumber"
class="form-control"
name="doctorNumber"
placeholder="Your doctorNumber" [(ngModel)]="model.doctorNumber"
(click)="open(content)"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="lastName">Last Name</label>
<input type="text"
id="lastName"
class="form-control"
name="lastName"
placeholder="Your lastName" [(ngModel)]="model.lastName"
#lastName="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && lastName.invalid }"
required maxlength="40"/>
<div *ngIf="f.submitted && lastName.invalid" class="invalid-input">
<div *ngIf="lastName.errors?.required">
Last Name is required
</div>
<div *ngIf="lastName.errors?.maxlength">
Last Name can have a maximum of 40 characters
</div>
</div>
</div>
<div class="col">
<label for="collectionCenter">Collection Center</label>
<input type="text"
id="collectionCenter"
class="form-control"
name="collectionCenter"
[(ngModel)]="model.collectionCenter" #collectionCenter="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && collectionCenter.invalid }"
required minlength="5" (keypress)="OnlyNumbersAllowed($event)"/>
<div *ngIf="f.submitted && collectionCenter.invalid" class="invalid-input">
<div *ngIf="collectionCenter.errors?.required">
Collection Center is required
</div>
<div *ngIf="collectionCenter.errors?.minlength">
Collection Center should be 5 digits in length
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="middleName">Middle Name</label>
<input type="text"
id="middleName"
class="form-control"
name="middleName"
placeholder="Your MiddleName" [(ngModel)]="model.middleName"/>
</div>
<div class="col">
<label for="state">State</label>
<input type="text"
id="state"
class="form-control"
name="state"
[(ngModel)]="model.state"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="sex">
Sex
</label>
<select id="sex" name="sex"
[(ngModel)]="model.sex" class="form-control">
<option *ngFor = "let sex of sexList" [ngValue]="sex.value">
{{sex.value}}
</option>
</select>
</div>
<div class="col">
<label for="billTo">Bill To</label>
<input type="text"
id="billTo"
class="form-control"
name="billTo"
[(ngModel)]="model.billTo" #billTo="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && billTo.invalid }"
minlength="3" maxlength="5"/>
<div *ngIf="f.submitted && billTo.invalid" class="invalid-input">
<div *ngIf="billTo.errors?.minlength">
Bill To should have a minimum of 3 characters
</div>
<div *ngIf="billTo.errors?.maxlength">
Bill To can have a maximum of 5 characters
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="dateOfBirth">Date Of Birth</label>
<input type="text" bsDatepicker [bsConfig]="datePickerConfig"
id="dateOfBirth"
class="form-control"
name="dateOfBirth"
[(ngModel)]="model.dateOfBirth"
#dateOfBirth="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && dateOfBirth.invalid }"
required/>
<div *ngIf="f.submitted && dateOfBirth.invalid" class="invalid-input">
<div *ngIf="dateOfBirth.errors?.required">
Date Of Birth is required
</div>
</div>
</div>
<div class="col">
<label for="bioRefId">BioRef ID</label>
<input type="text"
id="bioRefId"
class="form-control"
name="bioRefId"
[(ngModel)]="model.bioRefId"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="receivedDate">Received Date</label>
<input type="text" bsDatepicker [bsConfig]="datePickerConfig"
id="receivedDate"
class="form-control"
name="receivedDate"
[(ngModel)]="model.receivedDate"
#receivedDate="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && receivedDate.invalid }"
required/>
<div *ngIf="f.submitted && receivedDate.invalid" class="invalid-input">
<div *ngIf="receivedDate.errors?.required">
Received Date is required
</div>
</div>
</div>
<div class="col">
<label for="pid">PID</label>
<input type="text"
id="pid"
class="form-control"
name="pid"
[(ngModel)]="model.pid" #pid="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && pid.invalid }" maxlength="30"/>
<div *ngIf="f.submitted && pid.invalid" class="invalid-input">
<div *ngIf="pid.errors?.maxlength">
Patient Medical Record Number can have a maximum of 40 characters
</div>
</div>
</div>
</div>
<div class="row">
<div class="col">
<label for="receivedTime">Received Time</label>
<input type="text"
id="receivedTime"
class="form-control"
name="receivedTime"
[(ngModel)]="model.receivedTime"/>
</div>
<div class="col">
<label for="antiCoagulant">Anti-Coagulant</label>
<input type="text"
id="antiCoagulant"
class="form-control"
name="antiCoagulant"
[(ngModel)]="model.antiCoagulant"/>
</div>
</div>
<div class="row">
<div class="col">
<label for="collectionDate">Collection Date</label>
<input type="text" bsDatepicker [bsConfig]="datePickerConfig"
id="collectionDate"
class="form-control"
name="collectionDate"
[(ngModel)]="model.collectionDate" #collectionDate="ngModel"
[ngClass]="{ 'is-invalid' : f.submitted && collectionDate.invalid }"
required/>
<div *ngIf="f.submitted && collectionDate.invalid" class="invalid-input">
<div *ngIf="collectionDate.errors?.required">
Collection Date is required
</div>
</div>
</div>
<div class="col">
<label for="specimenType">
Specimen Type
</label>
<select id="specimenType" name="specimenType"
[(ngModel)]="model.specimenType" class="form-control">
<option *ngFor = "let spt of specimenTypeList" [ngValue]="spt.value">
{{spt.value}}
</option>
</select>
</div>
</div>
<div class="row">
<div class="col">
<label for="collectionTime">Collection Time</label>
<input type="text"
id="collectionTime"
class="form-control"
name="collectionTime"
[(ngModel)]="model.collectionTime"/>
</div>
<div class="col">
<label for="gptCode">GP Test Code</label>
<input type="text"
id="gptCode"
class="form-control"
name="gptCode"
[(ngModel)]="model.gptCode"/>
</div>
</div>
<div style="text-align:center">
<button type="submit" class="btn">
<span> Save</span>
</button>
</div>
</form>
<div class="offset-3"></div>
</div>
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Find Doctor</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form #f="ngForm">
<div class="row">
<div class="col">
<label for="lastname">Last Name</label>
<div class="input-group">
<input id="lastname" class="form-control" >
</div>
</div>
<div class="col">
<label for="upin">UPIN</label>
<div class="input-group">
<input id="upin" class="form-control" >
</div>
</div>
<div class="col">
<label for="code">Code</label>
<div class="input-group">
<input id="code" class="form-control" >
</div>
</div>
<div class="col">
<button type="submit" id="find" class="btn">
<span>Find</span>
</button>
</div>
</div>
<div class="row">
<div class="col">
<label for="firstname">First Name</label>
<div class="input-group">
<input id="firstname" class="form-control" >
</div>
</div>
<div class="col">
<label for="state">State</label>
<div class="input-group">
<input id="state" class="form-control" >
</div>
</div>
<div class="col">
<label for="extcode">Ext Code</label>
<div class="input-group">
<input id="extcode" class="form-control" >
</div>
</div>
<div class="col">
<button type="submit" id="Cancel" class="btn">
<span>Cancel</span>
</button>
</div>
</div>
</form>
</div>
</ng-template>
Here is my ts code
import { Component,OnInit } from '#angular/core';
import {HttpClient} from "#angular/common/http";
import {ModalDismissReasons, NgbModal} from '#ng-bootstrap/ng-bootstrap';
import { BsDatepickerConfig } from 'ngx-bootstrap/datepicker';
import { Sex } from '../models/sex.model';
import { SpecimenType } from '../models/specimenType.model';
#Component({
selector: 'app-direct-client-trf',
templateUrl: './direct-client-trf.component.html',
styleUrls: ['./direct-client-trf.component.css']
})
export class DirectClientTRFComponent implements OnInit {
closeResult: string;
OnlyNumbersAllowed(event:any){
const charCode = (event.which)?event.which:event.keycode;
if(charCode > 31 && (charCode < 48 || charCode > 57)){
console.log('charCode is restricted'+charCode);
return false;
}
return true;
}
datePickerConfig: Partial<BsDatepickerConfig>;
specimenTypeList:SpecimenType[] = [
{id: 1,value: 'P'},
{id: 2,value: 'W'}
];
sexList:Sex[] = [
{id: 1,value: 'M:Male'},
{id: 2,value: 'F:Female'},
{id: 3,value: 'U:Unknown'}
];
model:DirectTrfViewModel = {
accession:'',
template:'',
user:'',
count:'',
firstName:'',
lastName:'',
middleName:'',
sex:'',
dateOfBirth:'',
receivedDate:'',
receivedTime:'',
collectionDate:'',
collectionTime:'',
doctorNumber:'',
collectionCenter:'',
state:'',
billTo:'',
bioRefId:'',
pid:'',
antiCoagulant:'',
specimenType:'',
gptCode:''
};
constructor(private http:HttpClient,private modalService: NgbModal){
this.datePickerConfig = Object.assign({},
{
containerClass : 'theme-dark-blue',
showWeekNumbers: false,
dateInputFormat: 'MM/DD/YYYY'
});
}
ngOnInit(){
}
saveData():void{
let url = 'http://localhost:8080/api/directtrfsubmit';
this.http.post(url,this.model).subscribe(
res => {
location.reload();
},
err => {
alert('Error in saving data');
}
);
}
open(content:any) {
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}
export interface DirectTrfViewModel{
accession:string,
template:string,
user:string,
count:string,
firstName:string;
lastName:string;
middleName:string;
sex:string;
dateOfBirth:string;
receivedDate:string;
receivedTime:string;
collectionDate:string;
collectionTime:string;
doctorNumber:string;
collectionCenter:string;
state:string;
billTo:string;
bioRefId:string;
pid:string;
antiCoagulant:string;
specimenType:string;
gptCode:string;
}
With this the modal pop-up opens up and I need help in implementing the remaining functionality.

Ng-click validation is not working

I am beginer in angular js. I am validating a form with some input feild and form is posting on ng-click but validation is not working, validation message are displaying for a white then disappear i have to submit the form after validating. form ng-click should not be called untill the form is valid please help me . Thanks in advance.
<form name="teamForm" novalidate ng-submit="submit(teamForm)" class="formfields">
<div class="col-md-12">
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label for="lname">First Name:</label>
<input type="text" name="firstname"
ng-model="FirstName" class="form-control custom-form-control"
placeholder="First Name" required="required">
<span class="text-danger"
ng-show="(teamForm.firstname.$dirty || submitted) && teamForm.firstname.$error.required">Required</span>
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label for="lname">Last Name:</label>
<input type="text" name="lastname"
ng-model="LastName" class="form-control custom-form-control"
placeholder="Last Name" required="required">
<span class="text-danger"
ng-show="(teamForm.lastname.$dirty || submitted) && teamForm.lastname.$error.required">Required</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label for="email">Email:</label>
<input type="text" name="email"
ng-model="Email" class="form-control custom-form-control"
ng-pattern="/^[^\s#]+#[^\s#]+\.[^\s#]{2,}$/"
placeholder="Email" required="required">
<span class="text-danger"
ng-show="(teamForm.email.$dirty || submitted) && teamForm.email.$error.required">Required</span>
<span class="text-danger"
ng-show="teamForm.email.$dirty &&teamForm.email.$error.pattern">Please Enter Valid Email</span>
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label>Phone Number:</label>
<div class="clearfix"></div>
<input type="text" name="phone"
ng-model="Phone" class="form-control custom-form-control"
placeholder="XXXXXXXXXX" required="required">
<span class="text-danger"
ng-show="(teamForm.phone.$dirty || submitted) && teamForm.phone.$error.required">Required</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<label>Message:</label>
<textarea class="form-control rounded-0" rows="5"
name="comment" placeholder="Message"
ng-model="Comment" required="required"></textarea>
<span class="text-danger"
ng-show="(teamForm.comment.$dirty || submitted) && teamForm.comment.$error.required">Required</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<label>Upload Resume:</label>
<!--<input type="file" name="ResumePath" id="filehandler" />-->
<input type="file" id="file1" name="file" class="filelabel sr-only" multiple ng-files="getTheFiles($files)" onchange="Checkfiles($(this))" />
<!-- <input type="file" name="file" onchange="angular.element(this).scope().uploadFile(this.files)"/> -->
<label for="file1" class="form-control">
<span><i class="fa fa-file"></i> Drag file here or choose file</span>
</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<div vc-recaptcha key="'6Lc860IUAAAAAAyWI9WD8EV4eITu4ODdhuYHdzi8'"
class="grecaptcha" ng-model="respone1"></div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<button type="button" id="btnSubmit"
ng-click="uploadFiles()" value="Upload"
class="btn btn-green center-block pull-left">
<i class="fa fa-send"></i>{{btnText}}</button>
</div>
</div>
<div class="form-group text-center">
<h5 class="text-success" style="font-weight:bold">{{messagesuccess}}</h5>
<h5 class="text-danger" style="font-weight:bold">{{messageerror}}</h5>
</div>
</div>
</form>
ng-click (or it's vanilla cousin, onclick) do not check form validation. The function for submission needs to be defined at the form level, and then you specify which button acts as the submit button in order to get form behavior.
I see you already have a submit function defined. I assume you want to change that to uploadFiles. And if you want the form to conduct validation, remove the novalidation attribute.
<form name="teamForm" ng-submit="uploadFiles()" class="formfields">
then, for the button you would specify it is the submission button and remove the ng-click.
<button type="submit" id="btnSubmit"
value="Upload"
class="btn btn-green center-block pull-left">
<i class="fa fa-send"></i>{{btnText}}</button>

tabindex is not working with required attribute

<div class="row">
<div class="col-md-6">
<div class="form-body">
<div class="form-group">
<label>First Name</label>
<div class="input-group">
<input type="text" tabIndex="1" name="first_name" class="form-control">
</div>
</div>
<div class="form-group">
<label>Email Address</label>
<div class="input-group">
<input type="email" tabIndex="3" name="username" class="form-control" ng-model="username" required user-exist /><br/> <span style="color: red" ng-show="partnerForm.username.$touched && partnerForm.username.$invalid">
<span ng-show="partnerForm.username.$error.required">Email is required.</span>
<span ng-show="partnerForm.username.$error.email">Enter Correct Format.</span>
<span ng-show="partnerForm.username.$error.userExist">User already exists.</span>
</span>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-body">
<div class="form-group">
<label>Last Name</label>
<div class="input-group">
<input type="text" tabIndex="2" name="last_name" class="form-control">
</div>
</div>
</div>
</div>
</div>
the tabindex 3 is not working.i have checked by removing the required attr then it is working .the attributes required and tabindex is conflicting with each other.please help me to solve this.or provide a directive (working) for tabindex.

Not able to add validations to the elements in my form

I want to add validations to all the elements in the form. the error message should be displayed below the elements when the text of the control changes.
Following is my code:
<div role="tabpanel" class="tab-pane active" id="step-1">
<div class="col-md-4">
<div> <img src="../logo.jpg"
alt="Smiley face"
height="150"
style="margin:40px;"
width="150">
</div>
</div>
<div class="col-md-7">
<form action="r" name="regform"
method="post" >
<div class="col-md-6">
<div class="col-md-6" style="padding:0px;" >
<label for="mType" >Member Type*</label> <br />
<select id="member" ng-model="inputForm.mType" style="height:35px;width:135px;">
<option value="owner">Owner</option>
<option value="agent">Agent</option>
<option value="agent">Customer</option>
</select>
</div>
<div class="form-group">
<div class="col-md-6" style="padding:0px;" >
<label for="gender" >Gender </label> <br />
<select id="gender" ng-model="inputForm.gender" style="height:35px;width:135px;">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div class="form-group">
<label for=''>First Name</label>
<input type='name'
name='fName'
ng-model="inputForm.fName"
ng-minlength="1"
ng-maxlength="25"
ng-pattern="/^[A-Za-z]+$/"
required
/>
<span ng-show="regform.fName.$error.pattern">Please enter valid number!</span>
<!-- <span ng-show="studentForm.firstName.$touched && studentForm.firstName.$error.required">First name is required.</span>
<span ng-show="studentForm.lastName.$touched && studentForm.lastName.$error.minlength">min 3 chars.</span>
<span ng-show="studentForm.lastName.$touched && studentForm.lastName.$error.maxlength">Max 10 chars.</span>-->
</div>
<div class="form-group">
<label>Last Name : </label>
<input type="text"
name="lName"
class="form-control input-lg"
placeholder="Last Name"
ng-model="inputForm.lName"
style="height:35px">
</input>
</div>
<div class="form-group">
<label for="DOB">Date of Birth :</label>
<input type="date"
id="dob"
class="form-control input-lg"
placeholder="Date Of Birth (mm/dd/yyyy)"
ng-model="inputForm.dob"
style="height:35px;">
</input>
</div>
<div class="form-group">
<label>Adhar Number:</label>
<input type="text" id="adhar"
class="form-control input-lg"
placeholder="Adhar Number"
ng-model="inputForm.adhar"
style="height:35px">
</input>
</div>
<div class="form-group">
<label>PAN Number :</label>
<input type="text" id="pan"
class="form-control input-lg"
placeholder="PAN Number"
ng-model="inputForm.pan"
style="height:35px">
</input>
</div>
<div class="form-group">
<label>Email Address :</label>
<input type="email" id="email"
class="form-control input-lg"
placeholder="Your Email"
ng-model="inputForm.email"
style="height:35px">
</input>
<!-- <span ng-show="studentForm.email.$touched && studentForm.email.$error.email">Please enter valid email id.</span>-->
</div>
</div>
<div class="col-md-5" >
<div class="full-width bg-transparent">
<div class="full-width">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="custom-form">
<div class="text-center bg-form">
<div class="img-section">
<img src="http://lorempixel.com/200/200/nature/"
class="imgCircle"
alt="Profile picture">
<span class="fake-icon-edit"
id="PicUpload"
style="color: #ffffff;">
<span class="glyphicon glyphicon-camera camera"></span>
</span>
<div class="col-lg-12">
<h4 class="text-right col-lg-12" style="color:balck;">
<span class="glyphicon glyphicon-edit"></span> Edit Profile
</h4>
<input type="checkbox" class="form-control" id="checker"></input>
</div>
</div>
<input type="file"
id="image-input"
onchange="readURL(this);"
accept="image/*"
disabled class="form-control form-input Profile-input-file" >
</input>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-8" >
<hr class="colorgraph" style="height: 5px;
border-top: 0;
background: #62c2e4;
border-radius: 5px;">
<div class="col-xs-4 col-xs-offset-3">
<a ui-sref="form.account" class="btn btn-lg btn-primary btn-block signup-btn"
style=" height:35px;
margin-bottom:10px;
padding:0px;" >
Next <span class="glyphicon glyphicon-circle-arrow-right"></span>
</a>
</div>
</div>
</form>
</div>
</div>
image for reference
Please give suggestions to change the code so that appropriate error messages will be displayed to the controls after validating the input entr the user.
Your question is a bit vague as we can do what you are asking in many ways but find below an example using Bootstrap :
<form name="search" class="form-horizontal">
<div class="form-group col-md-2 required" ng-class="{
'has-feedback': (search.$submitted && search.carrier.$invalid),
'has-error': (search.$submitted && search.carrier.$invalid)}">
<label class="control-label" for="carrier">Carrier Code:</label>
<input type="text" class="form-control"
id="carrier" name="carrier"
required
pattern="[a-zA-Z0-9-]{2,3}"
maxlength="3"
ng-model="myAngularCtrl.flightDetails.carrier"/>
<span ng-show="search.$submitted && search.carrier.$error.required" class="field_errormsg-below">The Carrier Code is Mandatory</span>
<span ng-show="search.$submitted && search.carrier.$error.pattern" class="field_errormsg-below">use only numbers, digit and -</span>
</div>
<button type="submit"
class="btn btn-default FHU_margin-top-20"
ng-click="myAngularCtrl.searchFlight(search)">
Submit
</button>
</form>
You have a few things here:
The form has a name: search
You see two kind of error message being displayed. For them to be displayed, the user needs to have tried to submit the form (search.$submitted) and the field carrier needs to be in error (search.carrier.$error.required or search.carrier.$error.pattern)

ng-form in ng-repeat and checking the validation status of all forms

So, I have a parent form with a nested set of ng-forms like this:
<form class="row" name="parentForm" ng-repeat="model in controller.addresses track by $index" novalidate>
<div class="col-xs-12 row-title">
<h1>{{ model.type || 'Delivery' }} address</h1>
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
<div class="form" name="saveForm" ng-form>
<div class="form-group">
<label class="control-label">Company name</label>
<input class="form-control" name="company" type="text" placeholder="Enter your company name" ng-model="model.company" />
</div>
<div class="form-group" ng-class="{ 'has-error' : saveForm.address1.$invalid && !saveForm.address1.$pristine }">
<label class="control-label">House name/number</label>
<input class="form-control" name="houseName" type="text" placeholder="Please enter your address 1" ng-model="model.houseName" ng-minlength="3" required />
</div>
<div class="form-group">
<label class="control-label">Street</label>
<input class="form-control" name="street" type="text" placeholder="Please enter your address 2" ng-model="model.street" />
</div>
<div class="form-group">
<label class="control-label">Town</label>
<input class="form-control" name="town" type="text" placeholder="Please enter your address 3" ng-model="model.town" />
</div>
<div class="form-group">
<label class="control-label">County</label>
<input class="form-control" name="county" type="text" placeholder="Please enter your address 4" ng-model="model.county" />
</div>
<div class="form-group" ng-class="{ 'has-error' : saveForm.postCode.$invalid && !saveForm.postCode.$pristine }">
<label class="control-label">Post code</label>
<input class="form-control" name="postCode" type="text" placeholder="Enter your post code" ng-model="model.postCode" ng-minlength="3" required />
</div>
</div>
</div>
</form>
I then have a button:
<div class="row">
<div class="col-xs-12 col-sm-4 col-lg-4">
<div div class="row">
<div class="col-xs-6 tile">
<a class="red" ui-sref="^">
<i class="fa fa-trash"></i>
<div class="footer">Back</div>
</a>
</div>
<div class="col-xs-6 tile" ng-if="parentForm.$valid">
<a class="yellow" ui-sref="^.finance">
<i class="fa fa-arrow-right"></i>
<div class="footer">Continue</div>
</a>
</div>
</div>
</div>
</div>
I want this button to only show if all child forms are valid. I was hoping that I could just use parentForm.$valid but that doesn't work.
Does anyone know how to solve this?
Try to do parentForm.saveForm.$valid.
It will work
Nested forms aren't valid in HTML5 - but you can place your saveForm outside the parentForm and then use the input element's form attribute to specify a form for your input elements.
<form name="form1">
<input type="string" ng-model="form1input" required>
<input type="string" form="form2" ng-model="form2input" required>
</form>
<div ng-form="form2" id="form2"></div>
<button ng-if="form1.$valid && form2.$valid">Click</button>
Plunker: https://plnkr.co/edit/y9ipsNoEW596guLf2CzM?p=preview

Resources