Www.luxoft.com AngularJS Forms & validation. www.luxoft.com AngularJS form example <input type="text" name="firstName" ng-model="myForm.firstName">First.

Slides:



Advertisements
Similar presentations
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
Advertisements

© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
Video, audio, embed, iframe, HTML Form
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
3 November Building an Interactive Web Page: HTML Forms.
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Principles of Web Design 6 th Edition Chapter 11 – Web Forms.
HTML Forms – Interactive HTML – Web 2.0. HTML – New types for input – Degrades gracefully for browsers that do not support the html 5 input types
Tutorial #9 – Creating Forms. Tutorial #8 Review – Tables Borders (table, gridlines), Border-collapse: collapse; empty-cells: show; and rowspan, colspan.
JavaScript Form Validation
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
HTML Forms What is a form.
Forms and Form Controls Chapter What is a Form?
Jquery IS JQuery Jquery Example of mouseover event that shows a submenu when menu selected: $(‘#menu’).mouseover(function() { $(‘#submenu’).show();
Chapter 5 Java Script And Forms JavaScript, Third Edition.
JavaScript Lecture 6 Rachel A Ober
Suzanne J. Sultan Javascript Lecture 2. Suzanne J. Sultan function What is a function> Types of functions:  Function with no parameters  Function with.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 3.
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
1 Forms and Form elements CSD 340 McCoey. 2 Form Object Properties action Usually a call to a server elements encoding method post or get target Methods.
HTML Forms.
IDK0040 Võrgurakendused I harjutus 05: Forms Deniss Kumlander.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
HTML and FORMS.  A form is an area that can contain form elements.  Form elements are elements that allow the user to enter information (like text fields,
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
1 Review of Form Elements. 2 The tag Used in between tags.  Form elements(text control, buttons, etc.. ) goes here. OR  Form elements(text control,
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
AngularJS AJAX.
SYST Web Technologies SYST Web Technologies XHTML Forms.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
HTML5 Forms Forms are used to capture user input …
Unit 2 — The Exciting World of JavaScript Lesson 7 — Creating Forms with JavaScript.
Angular 2.
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Radio Buttons. Input/Form/Radio Group Use the dialog to enter label and values for the radio buttons.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
AngularJS $resource service. Add angular-resouce: Add the dependency: angular.module('myApp', ['ngResource']); Configure.
Check Boxes. 2 Check boxes  Image from:  HTML:  Each box gets it's own.
Web Forms. Web Forms: A form allows our web visitors to submit information to us. Some examples uses for forms are to let the web user contact us, fill.
HTML FORM. Form HTML Forms are used to select different kinds of user input. HTML forms are used to pass data to a server. A form can contain input elements.
© Luxoft Training. All rights reserved AngularJS Introduction.
JavaScript, Sixth Edition
IS1500: Introduction to Web Development
Web Forms.
Making your HTML Page Interactive
Web Forms.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
MIS Professor Sandvig MIS 324 Professor Sandvig
Introduction to HTML Forms and Servlets
Forms Web Design Ms. Olifer.
>> More on HTML Forms
>> Form Data Retrieval in JavaScript
Web Programming– UFCFB Lecture 17
النماذج عند الانتهاء من هذا الدرس ستكون قادرا على:
Designing Forms Lesson 10.
Objectives Explore web forms Work with form servers
Events: Changed and Input
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
Lesson 6: Web Forms.
Kanida Sinmai HTML Form Kanida Sinmai
Web Forms.
Making your HTML Page Interactive
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

AngularJS Forms & validation

AngularJS form example <input type="text" name="firstName" ng-model="myForm.firstName">First name <input type="text" name="lastName" ng-model="myForm.lastName">Last name {{myForm.firstName}} {{myForm.lastName}} angular.module("myapp", []).controller("MyController", function($scope) { $scope.myForm = {}; $scope.myForm.firstName = "Jakob"; $scope.myForm.lastName = "Jenkov"; } );

Checkboxes and radiobuttons <input type="checkbox" ng-model="myForm.wantNewsletter” ng-true-value="yes" ng-false-value="no" > <input type="radio" ng-model="myForm.whichNewsletter" value="weeklyNews"> <input type="radio" ng-model="myForm.whichNewsletter" value="monthlyNews">

Select <select ng-model="myForm.car" ng-options="obj.id as obj.name for obj in myForm.options“> Please choose a car angular.module("myapp", []).controller("MyController", function($scope) { $scope.myForm = {}; $scope.myForm.car = "nissan"; $scope.myForm.options = [ { id : "nissan", name: "Nissan" }, { id : "toyota", name: "Toyota" }, { id : "fiat", name: "Fiat" }]; } );

Form validation <input type="text" id="name" ng-model="myForm.name" ng-minlength="5" ng-maxlength="12"> Name angular.module("myapp", []).controller("MyController", function($scope) { $scope.myForm = {}; $scope.myForm.name = "Jakob Jenkov"; } ); <input type="text" id="name" ng-model="myForm.name” ng-pattern="/^\d+$/”> ng-required directive checks if the value of the form field is empty or not

Form check results

Using the "name" Attribute <input type="text" ng-model="user.firstLastName" name="firstLastName" placeholder="Enter Name"> Adding the "name" attribute to the form adds the FormController to the scope by that name Adding the "name" attribute to a control with the ngModel directive adds that ngModelController for that control to the FormController This is useful if one wants to check the state of the form or control programmatically

Form and elements validation results

Form check: change css for invalid field <input type="text" ng-class="myFormNg.name.$valid ? ’fieldValid’ : ‘fieldInvalid’ " name="name" ng-model="myForm.name" ng-minlength="2"> Name

Form check: show message <form name="myFormNg" ng-submit="myForm.submitTheForm()" novalidate> <input type="text" ng-class="myForm.getFormFieldCssClass(myFormNg.name2)" id="name1" name="name2" ng-model="myForm.name3" ng-minlength="2"> Name You must enter a valid name. Disable button: Submit

Submitting the form You can submit a form in two ways: Using a button element with an ng-click attribute. Using an ng-submit attribute (directive) on the form element. <input type="text" id="name" ng-model="myForm.name" ng-minlength="5" ng-maxlength="12"> Name Nissan Toyota Fiat

Submitting the form $scope.myForm.submitTheForm = function(item, event) { console.log("--> Submitting form"); var dataObject = { name : $scope.myForm.name, car : $scope.myForm.car }; var p = $http.post(”process.jsp", dataObject, {}); p.success(function(dataFromServer) { console.log(dataFromServer.title); }); p.error(function(data) { alert("Submitting form failed!"); }); }

Custom validation

ngModelController

Parsers and formatters $scope.account.value = ; $ Account value: function format (value) { return "$“+value; } form.acc.$formatters.push(format) function parse(value) { return value.substr(1); } form.acc.$parsers.push(parse); $formatters $parsers

ngModelController

Custom validator ngModel.$validators.onlyNumbers = function(modelValue, viewValue) { var value = modelValue || viewValue; return /[0-9]+/.test(value); }; ngModel.$error.onlyNumbers – results of validation in this method ngModel.$valid – result of validation in all validators

Custom async validator ngModel.$asyncValidators.uniqueUsername = function(modelValue, viewValue) { var value = modelValue || viewValue; return $http.get('/api/users/' + value). // Lookup user then(function resolved() { //username exists, this means validation fails return $q.reject('exists'); }, function rejected() { //username does not exist - this validation passes return true; }); };

Methods to set validity