elmentui 表单验证问题
<template>
<div class="container">
<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px">
<el-form-item label="礼包名称" prop="name">
<el-input v-model.trim="ruleForm.name"></el-input>
</el-form-item>
<el-form-item label="礼包金额(元)" prop="money">
<el-input-number
v-model="ruleForm.money"
:min="1"
controls-position="right"
style="width: 200px"
></el-input-number>
</el-form-item>
<el-form-item label="倒计时时间" prop="countDown">
<el-input-number
v-model="ruleForm.countDown"
:min="1"
controls-position="right"
style="width: 200px"
></el-input-number>
</el-form-item>
<el-form-item :rules="[
{ minTime: ruleForm.available_after, validator: validateRate, trigger: 'blur' },
{required: true, message: '上线时间', trigger: 'blur'},
]" label="上线时间" prop="available_after">
<el-date-picker
v-model="ruleForm.available_after"
format="yyyy-MM-dd HH:mm"
placeholder="选择上线时间"
size="small"
type="datetime"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item :rules="[
{ maxTime: ruleForm.available_before, validator: validateRate, trigger: 'blur' },
{required: true, message: '下线时间', trigger: 'blur'},
]" label="下线时间" prop="available_before">
<el-date-picker
v-model="ruleForm.available_before"
format="yyyy-MM-dd HH:mm"
placeholder="选择下线时间"
size="small"
type="datetime"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
ruleForm: {
name: '',
money: '',
countDown: 1,
available_after: '',
available_before: ''
},
rules: {
name: [
{required: true, message: '请输入礼包名称', trigger: 'blur'},
],
money: [
{required: true, message: '请输入礼包金额', trigger: 'blur'},
],
countDown: [
{required: true, message: '请输入倒计时时间', trigger: 'blur'},
]
}
}
},
mounted() {
},
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
},
validateRate(rule, value, callback) {
console.log(this.$refs.ruleForm.fields)
// this.$refs.ruleForm.fields[0].validateMessage ='error'
console.log(this.ruleForm.available_before <= this.ruleForm.available_after)
if (this.ruleForm.available_before === '' && this.ruleForm.available_after === '') {
callback(new Error('请选择时间'))
} else if (this.ruleForm.available_before == '' && this.ruleForm.available_after || this.ruleForm.available_after == '' && this.ruleForm.available_before) {
callback()
} else if (this.ruleForm.available_before <= this.ruleForm.available_after) {
callback(new Error('最小功率不能大于最大功率'))
} else {
if(this.$refs.ruleForm.fields[3].validateMessage){
this.$refs.ruleForm.fields[3].clearValidate();
}
if(this.$refs.ruleForm.fields[4].validateMessage){
this.$refs.ruleForm.fields[4].clearValidate();
}
callback();
}
}
},
computed: {}
}
</script>
主动触发错误提示操作
this.$refs.ruleForm.fields[4].validateMessage='';
//移除该表单项的校验结果
this.$refs.ruleForm.fields[4].clearValidate();
elmentui 表单验证问题的更多相关文章
- elment-ui表单验证
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-widt ...
- jQuery学习之路(8)- 表单验证插件-Validation
▓▓▓▓▓▓ 大致介绍 jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 ...
- 玩转spring boot——AOP与表单验证
AOP在大多数的情况下的应用场景是:日志和验证.至于AOP的理论知识我就不做赘述.而AOP的通知类型有好几种,今天的例子我只选一个有代表意义的“环绕通知”来演示. 一.AOP入门 修改“pom.xml ...
- form表单验证-Javascript
Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(33)-MVC 表单验证
系列目录 注:本节阅读需要有MVC 自定义验证的基础,否则比较吃力 一直以来表单的验证都是不可或缺的,微软的东西还是做得比较人性化的,从webform到MVC,都做到了双向验证 单单的用js实现的前端 ...
- 实现跨浏览器html5表单验证
div:nth-of-type(odd){ float: left; clear: left; } .origin-effect > div:nth-of-type(even){ float: ...
- jQuery Validate 表单验证 — 用户注册简单应用
相信很多coder在表单验证这块都是自己写验证规则的,今天我们用jQuery Validate这款前端验证利器来写一个简单的应用. 可以先把我写的这个小demo运行试下,先睹为快.猛戳链接--> ...
- jquery validate表单验证插件-推荐
1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家. 1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素 3.鼠标离开后的正确.错误提示及鼠标移入时的帮 ...
- 表单验证插件之jquery.validate.js
提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...
- 走进AngularJs 表单及表单验证
年底了越来越懒散,AngularJs的学习落了一段时间,博客最近也没更新.惭愧~前段时间有试了一下用yeoman构建Angular项目,感觉学的差不多了想做个项目练练手,谁知遇到了一系列问题.yeom ...
随机推荐
- kafka集群under replicated分析
近期随着业务消息量增大,现网几套kafka集群频繁收到under repliacted告警,集合近期定位分析过程,主要有以下几个方面:1. 查看是否有主机挂掉,或近期是否有主机重启,通过kafdrop ...
- 腾讯云静态资源放到cos存储桶里,并开启CDN自定义域名加速
首先根据腾讯云cos对应文档创建cos存储桶(权限为共有读私有写),上传build之后的静态文件到存储桶根目录,然后配置静态网站,然后访问静态网站的访问节点,如果报错请配置索引文档和错误文档为inde ...
- 莫烦Python 4
莫烦Python 4 新建模板小书匠 RNN Classifier 循环神经网络 问题描述 使用RNN对MNIST里面的图片进行分类 关键 SimpleRNN()参数 batch_input_shap ...
- tkinter的after函数的使用方法
1,模块tkinter里面没有aften函数,aften是部分类的类方法. import tkinter l = dir(tkinter) for s in l: if 'after' in eval ...
- 关于windows更新时间,设置更新时间段
https://jingyan.baidu.com/article/bad08e1eda412f09c85121c6.html https://www.dadighost.com/help/39372 ...
- Spring不同版本的AOP
1.Spring4.SpringBoot1 1.1 代码实现 public interface Calculator { int div(int a,int b); } @Component publ ...
- JVM运行时内存区
JVM运行时内存区是如何划分的? 方法区(Method Area):存储类的字节码信息.常量池 堆区(Heap Area):存储对象 Java方法栈(Stack Area):所有方法运行时,会创建一 ...
- 官网jdk8,jdk11下载时需要登录Oracle账号的问题解决
当到这一步骤时先勾选同意,在这个下载按钮上点鼠标右键复制链接地址 文件的下载地址 我们需要把地址做些修改.把等号前面的地址删掉,然后找到等号后面地址中的otn后面加上-pub 然后把这个地址直接复制到 ...
- 监听 view 初始化时
new ViewTreeObserverRegister().observe(getContentView(), new ViewTreeObserver.OnGlobalLayoutListener ...
- vs code + miktex配置
windows10系统通过choco安装miktex choco install miktex 添加path vscode配置: { // Latex workshop "latex-wor ...