内容简介:Intuitive APIs.
form-validation.js
ToC
Status: Beta
Live Examples
Feature
Intuitive APIs.
Asynchronous Rules Support.
Nested Object/Aray Support.
Array Manipulations (push, pop, shift, unshift, splice, reverse) Support.
Zero Dependencies, Native Javascript only.
Overview
const form = {
account: '',
}
const schema = {
account: {
$params: {
languageCode: 'en',
minLength: 6,
},
$normalizer({ value, key, parent, path, root, params }) {
return typeof value === 'string' ? value.trim() : ''
},
$rules: {
weak({ value, key, parent, path, root, params }) {
if (value.length < params.minLength) return 'Too short'
if (/\W/.test(value)) return 'Must contain special charachar'
},
async alreadyBeenUsed({ value, key, parent, path, root, params }) {
if (value === '') return
if (await isExists(value)) return false
},
},
$errors: {
weak({ value, key, parent, path, root, params }) {
return params.$rules.weak
},
alreadyBeenUsed({ value, key, parent, path, root, params }) {
const languageCode = params.languageCode || 'en-US'
return translate(`This account has already been used.`, { languageCode })
},
},
},
}
const valdiator = {}
// in order to track form's data sctructure (e.g., add new property to object, or push new element to array), you should always update your fields from the proxiedForm instead of the original form
const proxiedForm = FormValidation.proxy({ form, schema, validator })
// validate the entire form
await valdiator.$v.validate()
console.log(valdiator.$v.invalid)
// > true
console.log(valdiator.$v.errors.weak)
// > 'Too short.'
Docs
Need help?
Please open GitHub issues . Please search previous issues before creating a new issue.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Big C++中文版
霍斯特曼 / 姚爱红 / 电子工业 / 2007-3 / 85.00元
本书是一本关于C++的优秀教材,南圣何塞州立大学知名教授Horstmann编写。全书深入探讨了C++的知识,并着重强调了安全的标准模板库;本书较厚,但它可用做程序设计专业学生的教材(两学期)。全书在介绍基础知识后,作者论及了一些高级主题。书中面向对象的设计一章探讨了软件开发生命周期问题,给出了实现类关联的实用提示。其他高级主题包括模板,C++标准模板库,设计模式,GUI,关系数据库以及XML等。本......一起来看看 《Big C++中文版》 这本书的介绍吧!