
本文共 3693 字,大约阅读时间需要 12 分钟。
���������������������������������������������
���������������������������������������������������������������������������������������������������������������������������WxValidate������������������������������������������������������������������������������������������
������������������
���������������������������������WxValidate���������
������WxValidate.js���������������������������������������`utils`������������
������������������������������
������������������������������������������������������������WxValidate���������
// pages/[������������]/[���������].jsimport WxValidate from '../utils/WxValidate.js'Page({ data: { form: { name: '', // ������ idcard: '', // ������������ schoolName: '', // ������������ className: '', // ������ number: '' // ������ } }, onLoad: function() { this.initValidate(); }, showModal(error) { wx.showModal({ content: error.msg, showCancel: false }); }, initValidate() { const rules = { name: { required: true, minlength: 2 }, idcard: { required: true, idcard: true }, schoolName: { required: true }, className: { required: true }, number: { digits: true } }; const messages = { name: { required: '���������������', minlength: '������������������������' }, idcard: { required: '���������������������', idcard: '������������������������������' }, schoolName: { required: '���������������������' }, className: { required: '���������������' }, number: { digits: '������������������������' } }; this.WxValidate = new WxValidate(rules, messages); }, formSubmit(e) { const formData = e.detail.value; // ������������������ if (!this.WxValidate.checkForm(formData)) { const error = this.WxValidate.errorList[0]; this.showModal(error); return false; } // ��������������������� this.showModal({ msg: '���������������������' }); return true; }});
������������������������
WxValidate������������������������������������������������������������������������������������
������������
- rules: ���������������������������������������������������������������������������������
- messages: ������������������������������������������������������
������������������
checkForm(data)
���������������������������������data
������������������������rules
���������������errorList
������������������������������������C���������� ������ijkhain
������������������
������������������
- ������������������������
true
��� - ������������������������
false
���������������������������������������
���������������������������������
���������������������
- ������WxValidate.js���������������������������������������������������������������������
- ������������������������������_cache(_=__).
���������������������
- ���������fldrm����pe���
form-id
���submit-type
��������������������������� - ������
form
������������bindsubmit
���������������������������
���������������������������
- ������
WxValidate.errorList
���������������������������������������undefined
��������� - ������������������
console.log
���������������������
���������������������������������������������������������������������������������������������������WxValidate���������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������WxValidate���������������������������������������������
发表评论
最新留言
关于作者
