AngularJS manual form verification, angularjs form

Source: Internet
Author: User

AngularJS manual form verification, angularjs form

The so-called manual verification is through the AngularJS form attribute to verify, and become an AngularJS form must meet two conditions:

1. Add novalidate = "novalidate" to the form element ";

2. Add name = "theForm" to the form element ",

As follows:

<! DOCTYPE html> 

  • ● Adding novalidate = "novalidate" to form means that the form will no longer use the HTML5 verification feature
  • ● Adding name = "theForm" to form means that the form name is theForm. How to Use theForm, such as verifying whether the form has been modified by theForm. $ submitted
  • ● Submit a form through ng-submit
  • ● FormModel is an attribute in $ scope.
  • ● Manually verified the form Email and used many attributes of the AngularJS form, such as theForm. email. $ valid, theForm. $ pristine, theForm. $ submitted, theForm. email. $ error. required, theForm. email. $ error. email
  • ● Print all attributes of AngularJS forms using <pre >{{ theForm | json }}</pre>
{ "$error": { "required": [  {  "$validators": {},  "$asyncValidators": {},  "$parsers": [],  "$formatters": [   null  ],  "$viewChangeListeners": [],  "$untouched": true,  "$touched": false,  "$pristine": true,  "$dirty": false,  "$valid": false,  "$invalid": true,  "$error": {   "required": true  },  "$name": "email",  "$options": null  } ] }, "$name": "theForm", "$dirty": false, "$pristine": true, "$valid": false, "$invalid": true, "$submitted": false, "email": { "$validators": {}, "$asyncValidators": {}, "$parsers": [], "$formatters": [  null ], "$viewChangeListeners": [], "$untouched": true, "$touched": false, "$pristine": true, "$dirty": false, "$valid": false, "$invalid": true, "$error": {  "required": true }, "$name": "email", "$options": null }, "sex": { "$validators": {}, "$asyncValidators": {}, "$parsers": [], "$formatters": [], "$viewChangeListeners": [], "$untouched": true, "$touched": false, "$pristine": true, "$dirty": false, "$valid": true, "$invalid": false, "$error": {}, "$name": "sex", "$options": null }}

All inputs with the name attribute are displayed above.

The module, controller, and form submission methods are defined in the second. js file.

var myApp1 = angular.module('myApp1',[]);myApp1.controller('myCtrl1', function($scope, $http){ $scope.formModel = {}; $scope.onSubmit = function(){  $http.post('someurl',$scope.formModel)   .success(function(data){    console.log(':)');   })   .error(function(data){    console.log(':(');   });  console.log($scope.formModel); };});

The preceding form verification method is highly controllable but cumbersome.

The above is all the content of this article. We hope to be proficient in AngularJS manual form verification.

Articles you may be interested in:
  • AngularJS implements Form Verification
  • Detailed explanation of Form Verification programming in AngularJS
  • Details about how AngularJS implements Form Verification
  • AngularJs implements ng1.3 + Form Verification
  • AngularJS uses ngMessages for Form Verification
  • AngularJS uses angular-formly for Form Verification

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.