SlideShare a Scribd company logo
AngularJS Fundamentals
Data Entry Forms
Jim Duffy
TakeNote Technologies
© 2015 TakeNote Technologies
All Rights Reserved
Who Am I?
 Jim Duffy jduffy@takenote.com
 CEO/Founder of TakeNote Technologies www.takenote.com. We
provide web & mobile developer training and consulting
 Blog: www.geekswithblogs.net/takenote/
 Twitter: @jmduffy
 Microsoft Regional Director www.msrd.io
 11 time Microsoft Most Valuable Professional (MVP)
 HTML5, JavaScript, AngularJS, .NET, ASP.NET & SQL Server
Instructor, Mentor, Developer, and Consultant
 Experienced conference presenter
 Contributor to CODE Magazine
© 2015 TakeNote Technologies
All Rights Reserved
The Plan For This Session Is
 Data Binding Review
 Control Focus vs Data Model Focus
 Working With Input Elements
 Data Validation Attributes
 Data Entry States
 Show Validation Messages
 Use CSS Classes
 Form Submission Options
© 2015 TakeNote Technologies
All Rights Reserved
Data Binding Review
 One-way data binding
 ng-bind="Lastname"
 {{ Lastname }} syntax more common
 Two-way data binding
 ng-model="Lastname"
© 2015 TakeNote Technologies
All Rights Reserved
<div>
<label for="Lastname">Last Name:</label>
<input type="text"
name="Lastname"
ng-model="vm.Lastname" />
</div>
Data Binding Review
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 1
Control Focused Mindset
© 2015 TakeNote Technologies
All Rights Reserved
You’re stuck working
with the values as the
user sees them. This
means having to code
some transformations.
Control Focused Code
© 2015 TakeNote Technologies
All Rights Reserved
var city =
document.getElementById('city').value;
 Define a textbox
 Assign a value to a textbox
 Data is updated and Save button clicked
 Grab textbox value and assign to a var
document.getElementById('city').value =
‘Hollywood';
<input type="text" id="city" />
Data Model Focused Mindset
© 2015 TakeNote Technologies
All Rights Reserved
Data Model Focused Code
 Data model property (city) is bound to a
textbox
 User updates city textbox & data model
property (city) automagically reflects
user changes OR
 Data model property (city) is
programmatically changed and textbox
automagically reflects the change
 Controller works with a model not HTML
© 2015 TakeNote Technologies
All Rights Reserved
<input type="text" ng-model="city" />
ng-Model Directive
 Used to bind model value to view input
directive
 Provides validation behavior (required,
number, email, url)
 Keeps the state of the control (valid/invalid,
dirty/pristine, touched/untouched &
validation errors)
 Sets related css classes on the element (ng-
valid, ng-invalid, ng-dirty, ng-
pristine, ng-touched, ng-untouched)
 Registers the control with its parent form
© 2015 TakeNote Technologies
All Rights Reserved
Text-Based Input Directives
 Text Inputs
 Text
 Textarea
 Email
 URL
 Number
© 2015 TakeNote Technologies
All Rights Reserved
All support:
ng-model= "emp.Lastname"
required
ng-required="true/false"
ng-minlength = 2
ng-maxlength = 15
ng-pattern = "/^[a-z]+$/"
Text-Based Input Directives
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 2
Radio Button Inputs
 Used to provide a fixed group of options for a
model field
 Grouped by using the same model field
 HTML value attribute specifies value stored in
model
© 2015 TakeNote Technologies
All Rights Reserved
<label><input type="radio"
ng-model="employee.gender" value="M">Male
</label>
<label><input type="radio"
ng-model="employee.gender" value="F">Female
</label>
Radio Button Inputs
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 3
Checkbox Inputs
 Display a boolean input value
 Model field will contain true or false based on
checked status
 Optionally you can store different values in the
model based on ng-true-value and ng-false-
value.
© 2015 TakeNote Technologies
All Rights Reserved
<input type="checkbox“ ng-model="employee.status">
<input type="checkbox"
ng-model="employee.status"
ng-true-value="'Active'"
ng-false-value="'Inactive'">
Checkbox Inputs
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 4
Select Dropdown Inputs
 The select directive displays a dropdown list for
the user to select one or more items
 Can be populated statically or from an array in
the scope
 Option value = "" specifies which item to
display when bound model value doesn’t match
items in list
© 2015 TakeNote Technologies
All Rights Reserved
<select ng-model="employee.department">
<option value="sales">Sales</option>
<option value="admin“>Admin</option>
<option value="">-- No Selection --</option>
</select>
Select Dropdown Inputs
 Dynamically populating with ng-Options
directive
© 2015 TakeNote Technologies
All Rights Reserved
Controller Code:
vm.colorsArray = ["Red", "Green", "Blue"];
View Markup:
<select id="colorsArray"
ng-model=“selectedColor"
ng-options="color for color in vm.colorsArray">
<option value="">[No color]</option>
</select>
Select Dropdown Inputs
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 5
Data Validation Attributes
 ng-required: entry required
 ng-minlength: min string length
 ng-maxlength: max string length
 ng-pattern: regex comparison
 Visibility attributes review
 ng-show: Displays an element
 ng-hide: Hides an element
© 2015 TakeNote Technologies
All Rights Reserved
Data Validation Attributes
© 2015 TakeNote Technologies
All Rights Reserved
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text"
name="firstname"
autofocus
placeholder="Enter first name"
ng-required="true"
ng-model="firstname"
ng-minlength="2"
ng-maxlength="20"
ng-pattern="/^[a-z]+$/"
class="form-control" />
</div>
Data Entry States
 Properties
 $pristine: True if user has not
interacted with the form or control yet
 $dirty: True if user has already
interacted with the form or control
 $valid: True if there is no error on
the form or control
 $invalid: True if there is at least
one error on the form or control
© 2015 TakeNote Technologies
All Rights Reserved
Data Entry Control States #2
 Properties
 $touched: True if control has lost
focus
 $untouched: True if control has not
lost focus yet
 $error: Is an object hash,
containing references to controls or
forms with failing validators
© 2015 TakeNote Technologies
All Rights Reserved
Show Validation Messages
© 2015 TakeNote Technologies
All Rights Reserved
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" name="firstname" autofocus required
placeholder="Enter first name"
ng-model="firstname" ng-minlength="2"
ng-maxlength="20" ng-pattern="/^[a-z]+$/"
class="form-control" />
<div class="error-container"
ng-show="myForm.firstname.$dirty &&
myForm.firstname.$invalid">
<small class="error"
ng-show="myForm.firstname.$error.required">
First name is required.</small>
<small class="error"
ng-show="myForm.firstname.$error.minlength">
First name requires at least 2 char.</small>
<small class="error "
ng-show="myForm.firstname.$error.maxlength">
First Name cannot exceed 20 chars.</small>
</div>
</div>
 Use $dirty && $valid to
determine if there is an error
 Use $error to determine specific
error
Show Validation Messages
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 6
CSS Classes
CSS classes added & removed from elements
depending on the validity of the model:
 ng-pristine: Elements the user has
not interacted are added to this class
 ng-dirty: Elements the user has
interacted with are added to this class
 ng-valid: Elements that are valid are
added to this class
 ng-invalid: Elements that are not valid
are added to this class
© 2015 TakeNote Technologies
All Rights Reserved
CSS Classes #2
 ng-touched: Elements that have been
blurred are added to this class
 ng-untouched: Elements that have
not been blurred are added to this class
© 2015 TakeNote Technologies
All Rights Reserved
CSS Classes
© 2015 TakeNote Technologies
All Rights Reserved
form .ng-pristine {
background-color: #fffeb9;
}
form .ng-valid.ng-dirty {
background-color: lightgreen;
}
form .ng-invalid.ng-dirty {
background-color: #ff0000;
}
CSS Classes
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 7
Form Submission Events
 ng-submit
 Used at the <form> level to specify an
expression to be evaluated when form is
submitted
 Form submits when user presses Enter in an
input element or when button is clicked
 Use on forms with one input element and
only one button (Example: Search Form)
© 2015 TakeNote Technologies
All Rights Reserved
<form ng-submit="processForm(searchText)">
<input ng-model="searchText">
</form>
Form Submission Events
 ng-click
 Used on a button to specify a function to
run when clicked
© 2015 TakeNote Technologies
All Rights Reserved
<form>
<input ng-model=“firstName">
<input ng-model=“lastName">
…
<button ng-click="saveMeObiWan()">Save</button>
</form>
Form Submission Events
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 8
Canceling & Reverting Changes
 Done by creating a copy of the original model
© 2015 TakeNote Technologies
All Rights Reserved
vm.employee = {"firstname": "elmer",
"lastname": "FUDD", "email": "getwabbit@fake.com"
};
var vm.origEmp = angular.copy(vm.employee);
vm.revertAllEmployeeChanges = function() {
vm.employee = angular.copy(vm.origEmp);
vm.employeeForm.$setPristine();
};
vm.canRevert = function() {
return !angular.equals(vm.employee, vm.origEmp);
};
Canceling & Reverting Changes
© 2015 TakeNote Technologies
All Rights Reserved
DEMO 9
The Plan For This Session Was
 Data Binding Review
 Control Focus vs Data Model Focus
 Working With Input Elements
 Data Validation Attributes
 Data Entry States
 Show Validation Messages
 Use CSS Classes
 Form Submission Options
© 2015 TakeNote Technologies
All Rights Reserved
Resources
 https://www.angularjs.org/
 https://github.com/angular/angular.js
 https://docs.angularjs.org/guide
 https://blog.angularjs.org/
 http://www.angularjshub.com/
TakeNote Technologies
Hands On AngularJS Training Classes
© 2015 TakeNote Technologies
All Rights Reserved
Thank You for Attending!
 My contact info:
Jim Duffy
jduffy@takenote.com
TakeNote Technologies
www.takenote.com
Twitter: @jmduffy
© 2015 TakeNote Technologies
All Rights Reserved
TakeNote Technologies
© 2015 TakeNote Technologies
All Rights Reserved
Training Division
 Provides public and on-
site developer training
classes and mentoring
in:
 C#
 ASP.NET MVC
 SQL Server
 HTML5
 JavaScript
 AngularJS
 GrapeCity ActiveReports
Consulting Division
 Develops new web and mobile
solutions
 Develops cloud-based solutions
and migrate existing solutions
to the cloud
 Convert legacy solutions into
modern web & mobile solutions
 Manages new or existing
projects
 Supplements your development
team

More Related Content

Similar to AngularJS Fundamentals: Date Entry Forms

Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slides
Knoldus Inc.
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutes
Loiane Groner
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Rebecca Eloise Hogg
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
Automatic Value Propagation in Code Generator Templates
Automatic Value Propagation in Code Generator TemplatesAutomatic Value Propagation in Code Generator Templates
Automatic Value Propagation in Code Generator Templates
Robert Mencl
 
Mulesoft Meetup Roma - Monitoring Framework & DevOps.pptx
Mulesoft Meetup Roma - Monitoring Framework & DevOps.pptxMulesoft Meetup Roma - Monitoring Framework & DevOps.pptx
Mulesoft Meetup Roma - Monitoring Framework & DevOps.pptx
Alfonso Martino
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
EPAM Systems
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
New Form Element in HTML5
New Form Element in HTML5New Form Element in HTML5
New Form Element in HTML5
Zahra Rezwana
 
Test Automation Best Practices (with SOA test approach)
Test Automation Best Practices (with SOA test approach)Test Automation Best Practices (with SOA test approach)
Test Automation Best Practices (with SOA test approach)
Leonard Fingerman
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
Malla Reddy University
 
Selenium Openhouse CP-SAT - Handling Dynamic Web Tables
Selenium Openhouse CP-SAT - Handling Dynamic Web TablesSelenium Openhouse CP-SAT - Handling Dynamic Web Tables
Selenium Openhouse CP-SAT - Handling Dynamic Web Tables
Agile Testing Alliance
 
Whidbey old
Whidbey old Whidbey old
Whidbey old grenaud
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
Vishwanath KC
 
Baking In Quality: The Evolving Role of the Agile Tester
Baking In Quality: The Evolving Role of the Agile TesterBaking In Quality: The Evolving Role of the Agile Tester
Baking In Quality: The Evolving Role of the Agile Tester
TechWell
 
Brief on Device Awareness and Content Adaptation
Brief on Device Awareness and Content AdaptationBrief on Device Awareness and Content Adaptation
Brief on Device Awareness and Content Adaptation
tawi123
 
Angular 2 - An Introduction
Angular 2 - An IntroductionAngular 2 - An Introduction
Angular 2 - An Introduction
NexThoughts Technologies
 
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
 
Html javascript
Html javascriptHtml javascript
Html javascript
Soham Sengupta
 

Similar to AngularJS Fundamentals: Date Entry Forms (20)

Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slides
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutes
 
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis LazuliGetting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Automatic Value Propagation in Code Generator Templates
Automatic Value Propagation in Code Generator TemplatesAutomatic Value Propagation in Code Generator Templates
Automatic Value Propagation in Code Generator Templates
 
Mulesoft Meetup Roma - Monitoring Framework & DevOps.pptx
Mulesoft Meetup Roma - Monitoring Framework & DevOps.pptxMulesoft Meetup Roma - Monitoring Framework & DevOps.pptx
Mulesoft Meetup Roma - Monitoring Framework & DevOps.pptx
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
TapoResume2015
TapoResume2015TapoResume2015
TapoResume2015
 
New Form Element in HTML5
New Form Element in HTML5New Form Element in HTML5
New Form Element in HTML5
 
Test Automation Best Practices (with SOA test approach)
Test Automation Best Practices (with SOA test approach)Test Automation Best Practices (with SOA test approach)
Test Automation Best Practices (with SOA test approach)
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Selenium Openhouse CP-SAT - Handling Dynamic Web Tables
Selenium Openhouse CP-SAT - Handling Dynamic Web TablesSelenium Openhouse CP-SAT - Handling Dynamic Web Tables
Selenium Openhouse CP-SAT - Handling Dynamic Web Tables
 
Whidbey old
Whidbey old Whidbey old
Whidbey old
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
 
Baking In Quality: The Evolving Role of the Agile Tester
Baking In Quality: The Evolving Role of the Agile TesterBaking In Quality: The Evolving Role of the Agile Tester
Baking In Quality: The Evolving Role of the Agile Tester
 
Brief on Device Awareness and Content Adaptation
Brief on Device Awareness and Content AdaptationBrief on Device Awareness and Content Adaptation
Brief on Device Awareness and Content Adaptation
 
Angular 2 - An Introduction
Angular 2 - An IntroductionAngular 2 - An Introduction
Angular 2 - An Introduction
 
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
 
Html javascript
Html javascriptHtml javascript
Html javascript
 

Recently uploaded

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

AngularJS Fundamentals: Date Entry Forms

  • 1. AngularJS Fundamentals Data Entry Forms Jim Duffy TakeNote Technologies © 2015 TakeNote Technologies All Rights Reserved
  • 2. Who Am I?  Jim Duffy jduffy@takenote.com  CEO/Founder of TakeNote Technologies www.takenote.com. We provide web & mobile developer training and consulting  Blog: www.geekswithblogs.net/takenote/  Twitter: @jmduffy  Microsoft Regional Director www.msrd.io  11 time Microsoft Most Valuable Professional (MVP)  HTML5, JavaScript, AngularJS, .NET, ASP.NET & SQL Server Instructor, Mentor, Developer, and Consultant  Experienced conference presenter  Contributor to CODE Magazine © 2015 TakeNote Technologies All Rights Reserved
  • 3. The Plan For This Session Is  Data Binding Review  Control Focus vs Data Model Focus  Working With Input Elements  Data Validation Attributes  Data Entry States  Show Validation Messages  Use CSS Classes  Form Submission Options © 2015 TakeNote Technologies All Rights Reserved
  • 4. Data Binding Review  One-way data binding  ng-bind="Lastname"  {{ Lastname }} syntax more common  Two-way data binding  ng-model="Lastname" © 2015 TakeNote Technologies All Rights Reserved <div> <label for="Lastname">Last Name:</label> <input type="text" name="Lastname" ng-model="vm.Lastname" /> </div>
  • 5. Data Binding Review © 2015 TakeNote Technologies All Rights Reserved DEMO 1
  • 6. Control Focused Mindset © 2015 TakeNote Technologies All Rights Reserved You’re stuck working with the values as the user sees them. This means having to code some transformations.
  • 7. Control Focused Code © 2015 TakeNote Technologies All Rights Reserved var city = document.getElementById('city').value;  Define a textbox  Assign a value to a textbox  Data is updated and Save button clicked  Grab textbox value and assign to a var document.getElementById('city').value = ‘Hollywood'; <input type="text" id="city" />
  • 8. Data Model Focused Mindset © 2015 TakeNote Technologies All Rights Reserved
  • 9. Data Model Focused Code  Data model property (city) is bound to a textbox  User updates city textbox & data model property (city) automagically reflects user changes OR  Data model property (city) is programmatically changed and textbox automagically reflects the change  Controller works with a model not HTML © 2015 TakeNote Technologies All Rights Reserved <input type="text" ng-model="city" />
  • 10. ng-Model Directive  Used to bind model value to view input directive  Provides validation behavior (required, number, email, url)  Keeps the state of the control (valid/invalid, dirty/pristine, touched/untouched & validation errors)  Sets related css classes on the element (ng- valid, ng-invalid, ng-dirty, ng- pristine, ng-touched, ng-untouched)  Registers the control with its parent form © 2015 TakeNote Technologies All Rights Reserved
  • 11. Text-Based Input Directives  Text Inputs  Text  Textarea  Email  URL  Number © 2015 TakeNote Technologies All Rights Reserved All support: ng-model= "emp.Lastname" required ng-required="true/false" ng-minlength = 2 ng-maxlength = 15 ng-pattern = "/^[a-z]+$/"
  • 12. Text-Based Input Directives © 2015 TakeNote Technologies All Rights Reserved DEMO 2
  • 13. Radio Button Inputs  Used to provide a fixed group of options for a model field  Grouped by using the same model field  HTML value attribute specifies value stored in model © 2015 TakeNote Technologies All Rights Reserved <label><input type="radio" ng-model="employee.gender" value="M">Male </label> <label><input type="radio" ng-model="employee.gender" value="F">Female </label>
  • 14. Radio Button Inputs © 2015 TakeNote Technologies All Rights Reserved DEMO 3
  • 15. Checkbox Inputs  Display a boolean input value  Model field will contain true or false based on checked status  Optionally you can store different values in the model based on ng-true-value and ng-false- value. © 2015 TakeNote Technologies All Rights Reserved <input type="checkbox“ ng-model="employee.status"> <input type="checkbox" ng-model="employee.status" ng-true-value="'Active'" ng-false-value="'Inactive'">
  • 16. Checkbox Inputs © 2015 TakeNote Technologies All Rights Reserved DEMO 4
  • 17. Select Dropdown Inputs  The select directive displays a dropdown list for the user to select one or more items  Can be populated statically or from an array in the scope  Option value = "" specifies which item to display when bound model value doesn’t match items in list © 2015 TakeNote Technologies All Rights Reserved <select ng-model="employee.department"> <option value="sales">Sales</option> <option value="admin“>Admin</option> <option value="">-- No Selection --</option> </select>
  • 18. Select Dropdown Inputs  Dynamically populating with ng-Options directive © 2015 TakeNote Technologies All Rights Reserved Controller Code: vm.colorsArray = ["Red", "Green", "Blue"]; View Markup: <select id="colorsArray" ng-model=“selectedColor" ng-options="color for color in vm.colorsArray"> <option value="">[No color]</option> </select>
  • 19. Select Dropdown Inputs © 2015 TakeNote Technologies All Rights Reserved DEMO 5
  • 20. Data Validation Attributes  ng-required: entry required  ng-minlength: min string length  ng-maxlength: max string length  ng-pattern: regex comparison  Visibility attributes review  ng-show: Displays an element  ng-hide: Hides an element © 2015 TakeNote Technologies All Rights Reserved
  • 21. Data Validation Attributes © 2015 TakeNote Technologies All Rights Reserved <div class="form-group"> <label for="firstname">First Name:</label> <input type="text" name="firstname" autofocus placeholder="Enter first name" ng-required="true" ng-model="firstname" ng-minlength="2" ng-maxlength="20" ng-pattern="/^[a-z]+$/" class="form-control" /> </div>
  • 22. Data Entry States  Properties  $pristine: True if user has not interacted with the form or control yet  $dirty: True if user has already interacted with the form or control  $valid: True if there is no error on the form or control  $invalid: True if there is at least one error on the form or control © 2015 TakeNote Technologies All Rights Reserved
  • 23. Data Entry Control States #2  Properties  $touched: True if control has lost focus  $untouched: True if control has not lost focus yet  $error: Is an object hash, containing references to controls or forms with failing validators © 2015 TakeNote Technologies All Rights Reserved
  • 24. Show Validation Messages © 2015 TakeNote Technologies All Rights Reserved <div class="form-group"> <label for="firstname">First Name:</label> <input type="text" name="firstname" autofocus required placeholder="Enter first name" ng-model="firstname" ng-minlength="2" ng-maxlength="20" ng-pattern="/^[a-z]+$/" class="form-control" /> <div class="error-container" ng-show="myForm.firstname.$dirty && myForm.firstname.$invalid"> <small class="error" ng-show="myForm.firstname.$error.required"> First name is required.</small> <small class="error" ng-show="myForm.firstname.$error.minlength"> First name requires at least 2 char.</small> <small class="error " ng-show="myForm.firstname.$error.maxlength"> First Name cannot exceed 20 chars.</small> </div> </div>  Use $dirty && $valid to determine if there is an error  Use $error to determine specific error
  • 25. Show Validation Messages © 2015 TakeNote Technologies All Rights Reserved DEMO 6
  • 26. CSS Classes CSS classes added & removed from elements depending on the validity of the model:  ng-pristine: Elements the user has not interacted are added to this class  ng-dirty: Elements the user has interacted with are added to this class  ng-valid: Elements that are valid are added to this class  ng-invalid: Elements that are not valid are added to this class © 2015 TakeNote Technologies All Rights Reserved
  • 27. CSS Classes #2  ng-touched: Elements that have been blurred are added to this class  ng-untouched: Elements that have not been blurred are added to this class © 2015 TakeNote Technologies All Rights Reserved
  • 28. CSS Classes © 2015 TakeNote Technologies All Rights Reserved form .ng-pristine { background-color: #fffeb9; } form .ng-valid.ng-dirty { background-color: lightgreen; } form .ng-invalid.ng-dirty { background-color: #ff0000; }
  • 29. CSS Classes © 2015 TakeNote Technologies All Rights Reserved DEMO 7
  • 30. Form Submission Events  ng-submit  Used at the <form> level to specify an expression to be evaluated when form is submitted  Form submits when user presses Enter in an input element or when button is clicked  Use on forms with one input element and only one button (Example: Search Form) © 2015 TakeNote Technologies All Rights Reserved <form ng-submit="processForm(searchText)"> <input ng-model="searchText"> </form>
  • 31. Form Submission Events  ng-click  Used on a button to specify a function to run when clicked © 2015 TakeNote Technologies All Rights Reserved <form> <input ng-model=“firstName"> <input ng-model=“lastName"> … <button ng-click="saveMeObiWan()">Save</button> </form>
  • 32. Form Submission Events © 2015 TakeNote Technologies All Rights Reserved DEMO 8
  • 33. Canceling & Reverting Changes  Done by creating a copy of the original model © 2015 TakeNote Technologies All Rights Reserved vm.employee = {"firstname": "elmer", "lastname": "FUDD", "email": "getwabbit@fake.com" }; var vm.origEmp = angular.copy(vm.employee); vm.revertAllEmployeeChanges = function() { vm.employee = angular.copy(vm.origEmp); vm.employeeForm.$setPristine(); }; vm.canRevert = function() { return !angular.equals(vm.employee, vm.origEmp); };
  • 34. Canceling & Reverting Changes © 2015 TakeNote Technologies All Rights Reserved DEMO 9
  • 35. The Plan For This Session Was  Data Binding Review  Control Focus vs Data Model Focus  Working With Input Elements  Data Validation Attributes  Data Entry States  Show Validation Messages  Use CSS Classes  Form Submission Options © 2015 TakeNote Technologies All Rights Reserved
  • 36. Resources  https://www.angularjs.org/  https://github.com/angular/angular.js  https://docs.angularjs.org/guide  https://blog.angularjs.org/  http://www.angularjshub.com/ TakeNote Technologies Hands On AngularJS Training Classes © 2015 TakeNote Technologies All Rights Reserved
  • 37. Thank You for Attending!  My contact info: Jim Duffy jduffy@takenote.com TakeNote Technologies www.takenote.com Twitter: @jmduffy © 2015 TakeNote Technologies All Rights Reserved
  • 38. TakeNote Technologies © 2015 TakeNote Technologies All Rights Reserved Training Division  Provides public and on- site developer training classes and mentoring in:  C#  ASP.NET MVC  SQL Server  HTML5  JavaScript  AngularJS  GrapeCity ActiveReports Consulting Division  Develops new web and mobile solutions  Develops cloud-based solutions and migrate existing solutions to the cloud  Convert legacy solutions into modern web & mobile solutions  Manages new or existing projects  Supplements your development team