SlideShare une entreprise Scribd logo
1  sur  38
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

Contenu connexe

Similaire à AngularJS Fundamentals for Data Entry Forms

Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnoldus Inc.
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutesLoiane 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 LazuliRebecca Eloise Hogg
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran 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 TemplatesRobert 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.pptxAlfonso Martino
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular ComponentsSquash Apps Pvt Ltd
 
New Form Element in HTML5
New Form Element in HTML5New Form Element in HTML5
New Form Element in HTML5Zahra 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
 
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 TablesAgile Testing Alliance
 
Whidbey old
Whidbey old Whidbey old
Whidbey old grenaud
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworksVishwanath 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 TesterTechWell
 
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 Adaptationtawi123
 
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-16Shashikant Bhongale
 

Similaire à AngularJS Fundamentals for Data 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
 

Dernier

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

AngularJS Fundamentals for Data 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