AngularJS uses angular-formly for Form Verification _ AngularJS

Source: Internet
Author: User
This article describes how AngularJS uses angular-formly for form verification. For more information, see when there are many fields in the verification form, at this time, you may want to put the html generation and verification logic in the controller. On the page, it may be like this:

 

Then, define each field in the controller and verify it. Angular-formly exists for this requirement.

In the controller, define fields in the array:

Vm. export alfields = [{key: 'First _ name', type: 'input', templateOptions: {type: 'text', label: 'surname ', placeholder: 'input surname ', required: true }},...]

Use the hideExpression field to define the hidden conditions:

{Key: 'under18', type: 'checkbox', templateOptions: {label: 'under 18 '}, hideExpression :'! Model. email '// not displayed before email verification fails}

Use the validators field to customize verification rules:

{Key: 'license ', type: 'input', templateOptions: {label: 'id card No.', placeholder: 'enter ID card No. '}, hideExpression :'! Model. province ', validators: {driversLicense: function ($ viewValue, $ modelValue, scope) {var value = $ modelValue | $ viewValue; if (value) {return validateDriversLicence (value) ;}}, expressionProperties: {'templateoptions. disabled ': function ($ viewValue, $ modelValue, scope) {if (scope. model. province = 'shandong province ') {return false;} return true ;}}}

First install: npm install angular-formly-templates-bootstrap api-check

Demo file structure:

Css/
.....Style.css
Node_modules/
Scripts/
... MainController. js
... Provinces. js [select options are provided, related provinces]

App. js

Index.html

Index.html

 
 
 

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.