SlideShare uma empresa Scribd logo
1 de 33
© 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

Mais conteúdo relacionado

Mais procurados

Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
ghhgj jhgh
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
Slideshare
 
Sql Authorization
Sql AuthorizationSql Authorization
Sql Authorization
Fhuy
 

Mais procurados (20)

Document Type Definition (DTD)
Document Type Definition (DTD)Document Type Definition (DTD)
Document Type Definition (DTD)
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Data frame operations
Data frame operationsData frame operations
Data frame operations
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
 
Sql commands
Sql commandsSql commands
Sql commands
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query Optimization
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Sql commands
Sql commandsSql commands
Sql commands
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql Authorization
Sql AuthorizationSql Authorization
Sql Authorization
 
Binary Search
Binary SearchBinary Search
Binary Search
 

Destaque

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 

Destaque (20)

AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
AngularJS Filters
AngularJS FiltersAngularJS Filters
AngularJS Filters
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
 
Curso AngularJS - 6. formularios
Curso AngularJS - 6. formulariosCurso AngularJS - 6. formularios
Curso AngularJS - 6. formularios
 
Curso AngularJS - 7. temas avanzados
Curso AngularJS - 7. temas avanzadosCurso AngularJS - 7. temas avanzados
Curso AngularJS - 7. temas avanzados
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
InterBase на разных устройствах быстрый старт. 2017-03-30
InterBase на разных устройствах быстрый старт. 2017-03-30 InterBase на разных устройствах быстрый старт. 2017-03-30
InterBase на разных устройствах быстрый старт. 2017-03-30
 
Angular JS - Javascript framework for superheroes
Angular JS - Javascript framework for superheroesAngular JS - Javascript framework for superheroes
Angular JS - Javascript framework for superheroes
 
angular-formly presentation
angular-formly presentationangular-formly presentation
angular-formly presentation
 
AngularJS
AngularJSAngularJS
AngularJS
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
App cache vs localStorage
App cache vs localStorageApp cache vs localStorage
App cache vs localStorage
 

Semelhante a Forms in AngularJS

Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
iamdangavin
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
Masahiro Akita
 

Semelhante a Forms in AngularJS (20)

Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
 
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
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
 
AngularJs - Part 3
AngularJs - Part 3AngularJs - Part 3
AngularJs - Part 3
 
angular-np-3
angular-np-3angular-np-3
angular-np-3
 
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
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
 
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
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
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
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
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
 
Daily notes
Daily notesDaily notes
Daily notes
 
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
 
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Outsourcing 3.0: the agile way
Outsourcing 3.0: the agile wayOutsourcing 3.0: the agile way
Outsourcing 3.0: the agile way
 
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
 

Mais de Eyal Vardi

Mais de Eyal Vardi (20)

Why magic
Why magicWhy magic
Why magic
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 
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)
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
 
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
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time CompilationAngular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
 
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
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
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
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 

Forms in AngularJS

  • 1. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 2. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 3. © 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
  • 4. © 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
  • 5. © 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
  • 6. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Data Binding
  • 7. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 8. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com  ng-model-options="{ updateOn: 'default blur', debounce: {'default': 500, 'blur': 0} }"
  • 9. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 10. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 11. © 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
  • 12. © 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}"]>
  • 13. © 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
  • 14. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Form Validations
  • 15. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 16. © 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
  • 17. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 18. © 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>
  • 19. © 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>
  • 20. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Custom Binding
  • 21. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 22. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 23. © 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>
  • 24. © 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; }; } } });
  • 25. © 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>
  • 26. © 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); }; } } });
  • 27. © 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>
  • 28. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com Custom Form Validations
  • 29. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com
  • 30. © 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']);
  • 31. © 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>
  • 32. © 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>
  • 33. © 2014 All rights reserved. Tel: 054-5-767-300, Email: evardi@gmail.com eyalvardi.wordpress.com

Notas do Editor

  1. $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).