SlideShare a Scribd company logo
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
<form name="myform" class="css-form" novalidate>
disable browser's native
form validation
Name: <input type="text" ng-model="user.name"/>
E-mail:<input type="email" ng-model="user.email" required/>
Gender:
<input type="radio" ng-model="user.gender" value="male"/> male
<input type="radio" ng-model="user.gender" value="female"/> female
</form>
<button ng-click="reset()"
ng-disabled="isUnchanged(user)">
RESET
</button>
<button ng-click="update(user)"
ng-disabled=“myform.$invalid || isUnchanged(user)">
SAVE
</button>
validation
<style type="text/css">
.css-form input.ng-invalid.ng-dirty {background-color: #FA787E;}
.css-form input.ng-valid.ng-dirty {background-color: #78FA89;}
</style>
Binding the input
element to scope
property
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
<!-- Expressions -->
Please type your name : {{name}}
<!-- Directives & Data Binding -->
Name: <input ng-model="name" value="..." />
Template
name :
Scope
value
elm.bind('keydown', … )
$scope.$watch('name', … )
Directive
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Form
 Name
 Email
 Age
 Submit function
 Reset function
Scope
Binding
Proxies
Server
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Data Binding
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
 ng-model-options="{
updateOn: 'default blur',
debounce: {'default': 500, 'blur': 0}
}"
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Types
 Text
 Checkbox
 File
 Password
 Email
 URL
 Number
 Range
 Date
Validations
 novalidate
 Required
 Pattern
 Minlength
 Maxlength
 Min
 Max
Status
 $error
 $pristine
 $dirty
 $valid
 $invalid
 $touched
 $untouched
 $pending
CSS
 ng-valid
 ng-invalid
 ng-pristine
 ng-dirty
 ng-touched
 ng-untouched
 ng-pending
Events
 ng-click
 ng-change
 ng-submit
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
<input type="checkbox"
ng-model="{string}"
[name="{string}"]
[ng-true-value="{string}"]
[ng-false-value="{string}"]
[ng-change="{string}"]>
<input type="email"
ng-model="{string}"
[name="{string}"]
[required]
[ng-required="{string}"]
[ng-minlength="{number}"]
[ng-maxlength="{number}"]
[ng-pattern="{string}"]>
<input type="number"
ng-model="{string}"
[name="{string}"]
[min="{string}"]
[max="{string}"]
[required]
[ng-required="{string}"]
[ng-minlength="{number}"]
[ng-maxlength="{number}"]
[ng-pattern="{string}"]
[ng-change="{string}"]> <input type="radio"
ng-model="{string}"
value="{string}"
[name="{string}"]
[ng-change="{string}"]>
<input type="text" | type="URL"
ng-model="{string}"
[name="{string}"]
[required]
[ng-required="{string}"]
[ng-minlength="{number}"]
[ng-maxlength="{number}"]
[ng-pattern="{string}"]
[ng-change="{string}"]>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Form
 $error
 $pristine
 $dirty
 $pending
NgModelController
<button
ng-click="update(user)"
ng-disabled="form.$invalid || isUnchanged(user)">
SAVE
</button>
<span
ng-show="f.uEmail.$dirty && f.uEmail.$invalid">
Invalid:
<span ng-show="form.uEmail.$error.email">
This is not a valid email.</span>
</span>
NgModelController
ng-model
 $valid
 $invalid
 $submitted
 $error
 $pristine
 $dirty
 $pending
 $valid
 $invalid
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Form Validations
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
$async
Validators
$parsers
$modelValue
ngModelController
$validators
$async
Validators
$validators
$format
ters
$view
Change
Listeners$render
Status
 $error
 $pristine
 $dirty
 $valid
 $invalid
 $touched
 $untouched
 $pending
$viewValue
$$lastCommittedViewValue
$commitViewValue
$rollbackViewValue
$$debounce
ViewValue
Commit
$setView
Value
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
ngModelController
($pristine, $dirty, $error, $valid, $invalid )
$setValidity()$setPristine()
<style type="text/css">
input.ng-invalid.ng-dirty {background-color: #FA787E;}
input.ng-valid.ng-dirty {background-color: #78FA89;}
</style>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
app.directive('contenteditable', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
// view -> model
elm.bind('blur', function() {
scope.$apply(function() {
ctrl.$setViewValue(elm.html());
});
});
// model -> view
ctrl.$render = function() {
elm.html(ctrl.$modelValue);
};
// load init value from DOM
ctrl.$setViewValue(elm.html());
}
};
});
<div ng-model="content" title="Click to edit" contentEditable="true" >Some</div>
<pre>model = {{content}}</pre>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Custom Binding
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
app.directive('smartFloat', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift( function (viewValue) {
if ( FLOAT_REGEXP.test(viewValue) ) {
// it is valid
ctrl.$setValidity('float', true);
return parseFloat(viewValue.replace(',', '.'));
} else {
// it is invalid, return undefined (no model update)
ctrl.$setValidity('float', false);
return undefined;
}
});
}
};
});
<div>
Length (float):
<input type="text" ng-model="length" name="length" smart-float />{{length}}<br />
<span ng-show="form.length.$error.float">This is not a valid float number!</span>
</div>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
mi.directive('validatePasswordCharacters', function () {
var REQUIRED_PATTERNS = [/d+/,/[a-z]+/,/[A-Z]+/,/W+/,/^S+$/];
return {
require: 'ngModel',
link: function ($scope, element, attrs, ngModel) {
ngModel.$validators.passwordCharacters = function (value) {
var status = true;
angular.forEach(REQUIRED_PATTERNS, function (pattern) {
status = status && pattern.test(value);
});
return status;
};
}
}
});
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
mi.directive('validatePasswordCharacters', function () {
var REQUIRED_PATTERNS = [/d+/,/[a-z]+/,/[A-Z]+/,/W+/,/^S+$/];
return {
require: 'ngModel',
link: function ($scope, element, attrs, ngModel) {
ngModel.$validators.passwordCharacters = function (value) {
var status = true;
angular.forEach(REQUIRED_PATTERNS, function (pattern) {
status = status && pattern.test(value);
});
return status;
};
}
}
});
<form name="myForm">
<div class="label">
<input name="myPassword" type="password" ng-model="data.password"
validate-password-characters required />
<div ng-if="myForm.myPassword.$error.required">
You did not enter a password
</div>
<div ng-if="myForm.myPassword.$error.passwordCharacters">
Your password must contain a numeric, uppercase and lowercase as
well as special characters
</div>
</div>
</form>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
ngModule.directive('usernameAvailableValidator', function($http) {
return {
require: 'ngModel',
link: function($scope, element, attrs, ngModel) {
ngModel.$asyncValidators.usernameAvailable = function(username) {
return $http.get('/api/username-exists?u=' + username);
};
}
}
});
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
ngModule.directive('usernameAvailableValidator', function($http) {
return {
require: 'ngModel',
link: function($scope, element, attrs, ngModel) {
ngModel.$asyncValidators.usernameAvailable = function(username) {
return $http.get('/api/username-exists?u=' + username);
};
}
}
});
<form name="myForm">
<!--
first the required, pattern and minlength validators are executed
and then the asynchronous username validator is triggered...
-->
<input type="text"
class="input"
name="username"
minlength="4"
maxlength="15"
ng-model="form.data.username"
pattern="^[-w]+$"
username-available-validator
placeholder="Choose a username for yourself"
required />
<div ng-if="myForm.myUsername.$pending">
Checking Username...
</div>
</form>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
Custom Form Validations
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
<script src="angular.js" />
<script src="angular-messages.js">
angular.module('app', ['ngMessages']);
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
<script type="text/javascript" src="angular-messages.js"></script>
<script type="text/javascript">
var ngModule = angular.module('myApp', ['ngMessages']);
</script>
<form name="myForm">
<input type="text" name="colorCode" ng-model="data.colorCode"
minlength="6" required />
<div ng-messages="myForm.colorCode.$error"
ng-if="myForm.$submitted || myForm.colorCode.$touched">
<div ng-message="required">...</div>
<div ng-message="minlength">...</div>
<div ng-message="pattern">...</div>
</div>
<nav class="actions">
<input type="submit" />
</nav>
</form>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
<script type="text/ng-template" id="my-custom-messages">
<div ng-message="required">This field is required</div>
<div ng-message="minlength">This field is too short</div>
</script>
<form name="myForm">
<input type="email" id="email" name="myEmail" ng-model="email"
minlength="5" required />
<div ng-messages="myForm.myEmail.$error"
ng-messages-include="my-custom-messages">
<div ng-message="required">You did not enter your email</div>
<div ng-message="email">Your email address is invalid</div>
</div>
</form>
© 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
eyalvardi.wordpress.com
Ad

More Related Content

What's hot (20)

User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15
koolkampus
 
VB.Net-Controls and events
VB.Net-Controls and eventsVB.Net-Controls and events
VB.Net-Controls and events
Prachi Sasankar
 
Chapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solvingChapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solving
Abdul Shah
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
Css ppt
Css pptCss ppt
Css ppt
Nidhi mishra
 
Php array
Php arrayPhp array
Php array
Core Lee
 
Basic Html Notes
Basic Html NotesBasic Html Notes
Basic Html Notes
NextGenr
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
SAMIR BHOGAYTA
 
Protection and security of operating system
Protection and security of operating systemProtection and security of operating system
Protection and security of operating system
Abdullah Khosa
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principles
saurabhshertukde
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to Html
Folasade Adedeji
 
Html formatting
Html formattingHtml formatting
Html formatting
Webtech Learning
 
HTML PPT.pdf
HTML PPT.pdfHTML PPT.pdf
HTML PPT.pdf
sunnyGupta325328
 
Software architecture design ppt
Software architecture design pptSoftware architecture design ppt
Software architecture design ppt
farazimlak
 
Loc and function point
Loc and function pointLoc and function point
Loc and function point
Mitali Chugh
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Unit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.pptUnit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.ppt
DrTThendralCompSci
 
Richtextbox
RichtextboxRichtextbox
Richtextbox
Amandeep Kaur
 
Risk management(software engineering)
Risk management(software engineering)Risk management(software engineering)
Risk management(software engineering)
Priya Tomar
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
abhilashagupta
 
User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15User Interface Design in Software Engineering SE15
User Interface Design in Software Engineering SE15
koolkampus
 
VB.Net-Controls and events
VB.Net-Controls and eventsVB.Net-Controls and events
VB.Net-Controls and events
Prachi Sasankar
 
Chapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solvingChapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solving
Abdul Shah
 
Basic Html Notes
Basic Html NotesBasic Html Notes
Basic Html Notes
NextGenr
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
SAMIR BHOGAYTA
 
Protection and security of operating system
Protection and security of operating systemProtection and security of operating system
Protection and security of operating system
Abdullah Khosa
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principles
saurabhshertukde
 
Software architecture design ppt
Software architecture design pptSoftware architecture design ppt
Software architecture design ppt
farazimlak
 
Loc and function point
Loc and function pointLoc and function point
Loc and function point
Mitali Chugh
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Unit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.pptUnit 1 - Introduction to Software Engineering.ppt
Unit 1 - Introduction to Software Engineering.ppt
DrTThendralCompSci
 
Risk management(software engineering)
Risk management(software engineering)Risk management(software engineering)
Risk management(software engineering)
Priya Tomar
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
abhilashagupta
 

Viewers also liked (20)

AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
Eyal Vardi
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
Eyal Vardi
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
Eyal Vardi
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
Eyal Vardi
 
AngularJS Filters
AngularJS FiltersAngularJS Filters
AngularJS Filters
Eyal Vardi
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
Eyal Vardi
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
Eyal Vardi
 
Curso AngularJS - 6. formularios
Curso AngularJS - 6. formulariosCurso AngularJS - 6. formularios
Curso AngularJS - 6. formularios
Álvaro Alonso González
 
Curso AngularJS - 7. temas avanzados
Curso AngularJS - 7. temas avanzadosCurso AngularJS - 7. temas avanzados
Curso AngularJS - 7. temas avanzados
Álvaro Alonso González
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 
InterBase на разных устройствах быстрый старт. 2017-03-30
InterBase на разных устройствах быстрый старт. 2017-03-30 InterBase на разных устройствах быстрый старт. 2017-03-30
InterBase на разных устройствах быстрый старт. 2017-03-30
sandy97
 
Angular JS - Javascript framework for superheroes
Angular JS - Javascript framework for superheroesAngular JS - Javascript framework for superheroes
Angular JS - Javascript framework for superheroes
Eugenio Minardi
 
angular-formly presentation
angular-formly presentationangular-formly presentation
angular-formly presentation
Annia Martinez
 
AngularJS
AngularJSAngularJS
AngularJS
Srivatsan Krishnamachari
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
jnewmanux
 
App cache vs localStorage
App cache vs localStorageApp cache vs localStorage
App cache vs localStorage
senthil_hi
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
Eyal Vardi
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
Eyal Vardi
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
Eyal Vardi
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
Eyal Vardi
 
AngularJS Filters
AngularJS FiltersAngularJS Filters
AngularJS Filters
Eyal Vardi
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
Eyal Vardi
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
Eyal Vardi
 
InterBase на разных устройствах быстрый старт. 2017-03-30
InterBase на разных устройствах быстрый старт. 2017-03-30 InterBase на разных устройствах быстрый старт. 2017-03-30
InterBase на разных устройствах быстрый старт. 2017-03-30
sandy97
 
Angular JS - Javascript framework for superheroes
Angular JS - Javascript framework for superheroesAngular JS - Javascript framework for superheroes
Angular JS - Javascript framework for superheroes
Eugenio Minardi
 
angular-formly presentation
angular-formly presentationangular-formly presentation
angular-formly presentation
Annia Martinez
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
jnewmanux
 
App cache vs localStorage
App cache vs localStorageApp cache vs localStorage
App cache vs localStorage
senthil_hi
 
Ad

Similar to Forms in AngularJS (20)

Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
Fred Moyer
 
Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16
Shashikant Bhongale
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
Eyal Vardi
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
Daisuke Komatsu
 
AngularJs - Part 3
AngularJs - Part 3AngularJs - Part 3
AngularJs - Part 3
Nishikant Taksande
 
angular-np-3
angular-np-3angular-np-3
angular-np-3
Nishikant Taksande
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
Eyal Vardi
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
iamdangavin
 
Dynamics 365 Web API - CRMUG April 2018
Dynamics 365 Web API - CRMUG April 2018Dynamics 365 Web API - CRMUG April 2018
Dynamics 365 Web API - CRMUG April 2018
Greg McMurray
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
Eyal Vardi
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
Marcus Ramberg
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
Patrick Reagan
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
Hugo Hamon
 
Beyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery SelectorsBeyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery Selectors
Alexander Shopov
 
Daily notes
Daily notesDaily notes
Daily notes
meghendra168
 
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesEWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
Rob Tweed
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
Masahiro Akita
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
Nishan Subedi
 
Outsourcing 3.0: the agile way
Outsourcing 3.0: the agile wayOutsourcing 3.0: the agile way
Outsourcing 3.0: the agile way
Alexey Krivitsky
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
Viget Labs
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
Fred Moyer
 
Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16
Shashikant Bhongale
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
Eyal Vardi
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
Daisuke Komatsu
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
Eyal Vardi
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
iamdangavin
 
Dynamics 365 Web API - CRMUG April 2018
Dynamics 365 Web API - CRMUG April 2018Dynamics 365 Web API - CRMUG April 2018
Dynamics 365 Web API - CRMUG April 2018
Greg McMurray
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
Eyal Vardi
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
Marcus Ramberg
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
Patrick Reagan
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
Hugo Hamon
 
Beyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery SelectorsBeyond the Final Frontier of jQuery Selectors
Beyond the Final Frontier of jQuery Selectors
Alexander Shopov
 
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesEWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
Rob Tweed
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
Masahiro Akita
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
Nishan Subedi
 
Outsourcing 3.0: the agile way
Outsourcing 3.0: the agile wayOutsourcing 3.0: the agile way
Outsourcing 3.0: the agile way
Alexey Krivitsky
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
Viget Labs
 
Ad

More from Eyal Vardi (20)

Why magic
Why magicWhy magic
Why magic
Eyal Vardi
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
Eyal Vardi
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
Eyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
Eyal Vardi
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
Eyal Vardi
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
Eyal Vardi
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
Eyal Vardi
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
Eyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
Eyal Vardi
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
Eyal Vardi
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
Eyal Vardi
 

Recently uploaded (20)

Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 

Forms in AngularJS

  • 1. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 2. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 3. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] <form name="myform" class="css-form" novalidate> disable browser's native form validation Name: <input type="text" ng-model="user.name"/> E-mail:<input type="email" ng-model="user.email" required/> Gender: <input type="radio" ng-model="user.gender" value="male"/> male <input type="radio" ng-model="user.gender" value="female"/> female </form> <button ng-click="reset()" ng-disabled="isUnchanged(user)"> RESET </button> <button ng-click="update(user)" ng-disabled=“myform.$invalid || isUnchanged(user)"> SAVE </button> validation <style type="text/css"> .css-form input.ng-invalid.ng-dirty {background-color: #FA787E;} .css-form input.ng-valid.ng-dirty {background-color: #78FA89;} </style> Binding the input element to scope property
  • 4. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] <!-- Expressions --> Please type your name : {{name}} <!-- Directives & Data Binding --> Name: <input ng-model="name" value="..." /> Template name : Scope value elm.bind('keydown', … ) $scope.$watch('name', … ) Directive
  • 5. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Form  Name  Email  Age  Submit function  Reset function Scope Binding Proxies Server
  • 6. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Data Binding
  • 7. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 8. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]  ng-model-options="{ updateOn: 'default blur', debounce: {'default': 500, 'blur': 0} }"
  • 9. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 10. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 11. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Types  Text  Checkbox  File  Password  Email  URL  Number  Range  Date Validations  novalidate  Required  Pattern  Minlength  Maxlength  Min  Max Status  $error  $pristine  $dirty  $valid  $invalid  $touched  $untouched  $pending CSS  ng-valid  ng-invalid  ng-pristine  ng-dirty  ng-touched  ng-untouched  ng-pending Events  ng-click  ng-change  ng-submit
  • 12. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] <input type="checkbox" ng-model="{string}" [name="{string}"] [ng-true-value="{string}"] [ng-false-value="{string}"] [ng-change="{string}"]> <input type="email" ng-model="{string}" [name="{string}"] [required] [ng-required="{string}"] [ng-minlength="{number}"] [ng-maxlength="{number}"] [ng-pattern="{string}"]> <input type="number" ng-model="{string}" [name="{string}"] [min="{string}"] [max="{string}"] [required] [ng-required="{string}"] [ng-minlength="{number}"] [ng-maxlength="{number}"] [ng-pattern="{string}"] [ng-change="{string}"]> <input type="radio" ng-model="{string}" value="{string}" [name="{string}"] [ng-change="{string}"]> <input type="text" | type="URL" ng-model="{string}" [name="{string}"] [required] [ng-required="{string}"] [ng-minlength="{number}"] [ng-maxlength="{number}"] [ng-pattern="{string}"] [ng-change="{string}"]>
  • 13. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Form  $error  $pristine  $dirty  $pending NgModelController <button ng-click="update(user)" ng-disabled="form.$invalid || isUnchanged(user)"> SAVE </button> <span ng-show="f.uEmail.$dirty && f.uEmail.$invalid"> Invalid: <span ng-show="form.uEmail.$error.email"> This is not a valid email.</span> </span> NgModelController ng-model  $valid  $invalid  $submitted  $error  $pristine  $dirty  $pending  $valid  $invalid
  • 14. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Form Validations
  • 15. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 16. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] $async Validators $parsers $modelValue ngModelController $validators $async Validators $validators $format ters $view Change Listeners$render Status  $error  $pristine  $dirty  $valid  $invalid  $touched  $untouched  $pending $viewValue $$lastCommittedViewValue $commitViewValue $rollbackViewValue $$debounce ViewValue Commit $setView Value
  • 17. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 18. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] ngModelController ($pristine, $dirty, $error, $valid, $invalid ) $setValidity()$setPristine() <style type="text/css"> input.ng-invalid.ng-dirty {background-color: #FA787E;} input.ng-valid.ng-dirty {background-color: #78FA89;} </style>
  • 19. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] app.directive('contenteditable', function() { return { require: 'ngModel', link: function(scope, elm, attrs, ctrl) { // view -> model elm.bind('blur', function() { scope.$apply(function() { ctrl.$setViewValue(elm.html()); }); }); // model -> view ctrl.$render = function() { elm.html(ctrl.$modelValue); }; // load init value from DOM ctrl.$setViewValue(elm.html()); } }; }); <div ng-model="content" title="Click to edit" contentEditable="true" >Some</div> <pre>model = {{content}}</pre>
  • 20. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Custom Binding
  • 21. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 22. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 23. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] app.directive('smartFloat', function () { return { require: 'ngModel', link: function (scope, elm, attrs, ctrl) { ctrl.$parsers.unshift( function (viewValue) { if ( FLOAT_REGEXP.test(viewValue) ) { // it is valid ctrl.$setValidity('float', true); return parseFloat(viewValue.replace(',', '.')); } else { // it is invalid, return undefined (no model update) ctrl.$setValidity('float', false); return undefined; } }); } }; }); <div> Length (float): <input type="text" ng-model="length" name="length" smart-float />{{length}}<br /> <span ng-show="form.length.$error.float">This is not a valid float number!</span> </div>
  • 24. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] mi.directive('validatePasswordCharacters', function () { var REQUIRED_PATTERNS = [/d+/,/[a-z]+/,/[A-Z]+/,/W+/,/^S+$/]; return { require: 'ngModel', link: function ($scope, element, attrs, ngModel) { ngModel.$validators.passwordCharacters = function (value) { var status = true; angular.forEach(REQUIRED_PATTERNS, function (pattern) { status = status && pattern.test(value); }); return status; }; } } });
  • 25. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] mi.directive('validatePasswordCharacters', function () { var REQUIRED_PATTERNS = [/d+/,/[a-z]+/,/[A-Z]+/,/W+/,/^S+$/]; return { require: 'ngModel', link: function ($scope, element, attrs, ngModel) { ngModel.$validators.passwordCharacters = function (value) { var status = true; angular.forEach(REQUIRED_PATTERNS, function (pattern) { status = status && pattern.test(value); }); return status; }; } } }); <form name="myForm"> <div class="label"> <input name="myPassword" type="password" ng-model="data.password" validate-password-characters required /> <div ng-if="myForm.myPassword.$error.required"> You did not enter a password </div> <div ng-if="myForm.myPassword.$error.passwordCharacters"> Your password must contain a numeric, uppercase and lowercase as well as special characters </div> </div> </form>
  • 26. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] ngModule.directive('usernameAvailableValidator', function($http) { return { require: 'ngModel', link: function($scope, element, attrs, ngModel) { ngModel.$asyncValidators.usernameAvailable = function(username) { return $http.get('/api/username-exists?u=' + username); }; } } });
  • 27. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] ngModule.directive('usernameAvailableValidator', function($http) { return { require: 'ngModel', link: function($scope, element, attrs, ngModel) { ngModel.$asyncValidators.usernameAvailable = function(username) { return $http.get('/api/username-exists?u=' + username); }; } } }); <form name="myForm"> <!-- first the required, pattern and minlength validators are executed and then the asynchronous username validator is triggered... --> <input type="text" class="input" name="username" minlength="4" maxlength="15" ng-model="form.data.username" pattern="^[-w]+$" username-available-validator placeholder="Choose a username for yourself" required /> <div ng-if="myForm.myUsername.$pending"> Checking Username... </div> </form>
  • 28. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] Custom Form Validations
  • 29. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected]
  • 30. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] <script src="angular.js" /> <script src="angular-messages.js"> angular.module('app', ['ngMessages']);
  • 31. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] <script type="text/javascript" src="angular-messages.js"></script> <script type="text/javascript"> var ngModule = angular.module('myApp', ['ngMessages']); </script> <form name="myForm"> <input type="text" name="colorCode" ng-model="data.colorCode" minlength="6" required /> <div ng-messages="myForm.colorCode.$error" ng-if="myForm.$submitted || myForm.colorCode.$touched"> <div ng-message="required">...</div> <div ng-message="minlength">...</div> <div ng-message="pattern">...</div> </div> <nav class="actions"> <input type="submit" /> </nav> </form>
  • 32. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] <script type="text/ng-template" id="my-custom-messages"> <div ng-message="required">This field is required</div> <div ng-message="minlength">This field is too short</div> </script> <form name="myForm"> <input type="email" id="email" name="myEmail" ng-model="email" minlength="5" required /> <div ng-messages="myForm.myEmail.$error" ng-messages-include="my-custom-messages"> <div ng-message="required">You did not enter your email</div> <div ng-message="email">Your email address is invalid</div> </div> </form>
  • 33. © 2014 All rights reserved. Tel: 054-5-767-300, Email: [email protected] eyalvardi.wordpress.com

Editor's Notes

  • #24: $setValidity(validationErrorKey, isValid) Change the validity state, and notifies the form when the control changes validity. (i.e. it does not notify form if given validator is already marked as invalid). This method should be called by validators - i.e. the parser or formatter functions. Parameters validationErrorKey – {string} – Name of the validator. the validationErrorKey will assign to $error[validationErrorKey]=isValid so that it is available for data-binding. ThevalidationErrorKey should be in camelCase and will get converted into dash-case for class name. Example: myError will result in ng-valid-my-error and ng-invalid-my-error class and can be bound to as {{someForm.someControl.$error.myError}} . isValid – {boolean} – Whether the current state is valid (true) or invalid (false).