E企盈营销工具技术服务商 热线:4006-838-530

小程序form表单验证

E企盈直播平台营销卖货系统

链接: https://pan.baidu.com/s/1XbxufnE4xVH3hJrzt1EXvg 提取码: 2yau 复制这段内容后打开百度网盘手机App,操作更方便哦这个是验证表单封装后的js,我也是下载过来的首先下载后放入utils里(当然自己写一个也没问题,我是直接下载,然后如果里面没有我想要的再添加)在需要用的页面js里引入import WxValidate from ‘../../../../utils/WxValidate.js’Page({  /**   * 页面的初始数据   */  data: {  },  //报错   showToast(error) {    wx.showToast({      title: error.msg,      icon: ‘none’    })  },  initValidate() {    const rules = {      businessType: {        required: true      },      limitedAt: {        required: true,      },      boxType: {        required: true,      },      boxCount: {        required: true,        intType: true      },      weight: {        required: true,        weight: true      },      store: {        required: true,      },      harbour: {        required: true,      },      freight: {        required: true,        money: true      },      freshInterval: {        required: true,      },      linkman: {        required: true,      },    }    const messages = {      businessType: {        required: ‘请选择业务类型’,      },      limitedAt: {        required: ‘请选择到厂时间’,      },      boxType: {        required: ‘请选择箱型’,      },      boxCount: {        required: ‘请输入发单数量’,        intType: ‘发单数量请输入10以内’      },      weight: {        required: ‘请输入箱重’,        weight: ‘箱重请填写100以内整数或两位小数’      },      store: {        required: ‘请输入门点地址’,      },      harbour: {        required: ‘请输入港区’,      },      freight: {        required: ‘请输入运费金额’,        money: ‘请输入正确的金额’      },      freshInterval: {        required: ‘请选择重发间隔’,      },      linkman: {        required: ‘请选择联系人’,      },    }    this.WxValidate = new WxValidate(rules, messages)  },/**   * 生命周期函数–监听页面加载   */  onLoad: function (options) {    this.initValidate() },// 提交  formSubmit: function(e) {    const params = e.detail.value    // 校验表单    if (!this.WxValidate.checkForm(params)) {      const error = this.WxValidate.errorList[0]      this.showToast(error)      return false    }},})注:initValidate()里验证的名字跟wxml里面的name值必须是一样

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 小程序form表单验证
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏