tags: vue resetFields clearValidate ref
Reprinted link: https: //blog.csdn.net/zuo_zuo_blog/article/details/101444920
1. check the entire form is removed
<Form ref="form" rule={this.rules}>
<FormItem prop="name" label="Full name">
<Input/>
</FormItem>
<FormItem prop="age" label="age">
<Input/>
</FormItem>
</Form>
// basis of determination conditions, remove all check table item
IF (/ * Condition * /) {
this.$refs['form'].clearValidate();
}
// But sometimes only need to remove an item check them, if only to remove the name of the check:
IF (/ * Condition * /) {
this.$refs['form'].clearValidate(['name']);
}
2.resetFields and clearValidate difference
. This $ refs.form.resetFields (); // check result removed and reset the field values
. This $ refs.form.clearValidate (); // remove the check results
// Both can clear validation, but resetFields () will reset the field values, and bound vue used in a large amount of data, is likely to occur
// same data binding in the case of many, if abuse resetFields is likely to cause inexplicable bug appears on the screen
3. Note
is possible this.refs [form] .clearValidate () does not recognize the way. Requires:. This refs [form] .clearValidate () does not recognize the way. Requires: this.refs [form] .clearValidate () does not recognize the way. Need to use: this.refs.form.clearValidate ();
4.element-ui in form validation
form code
<el-form :label-width="120" :rules="formRules" :model="form" ref="form">
<el-form-item label="Event name" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
</el-form>
<el-button type="info" @click="save">save</el-button>
<el-button type="info" @click="empty">Reset</el-button>
method
// check rules
formRules: {
name: [
{Required: true, message: 'Please enter a campaign name', trigger: 'blur'},
{Min: 3, max: 5, message: 'the length in characters 3-5', trigger: 'blur'}
],
}
/**
* Save function
*/
save() {
this.$refs[form].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});
}
// possible this. $ Refs [form] .validate () does not recognize the way. Need to use: this $ refs.form.validate ();.
})
empty () {// Reset
// according to the needs a second election
/**
* Removed and reset the check result field value
* Note: Clear and checking the values in the table item name
*/
this.$refs.form.resetFields();
/**
* Remove the check results
* NOTE: Only clear checklist item name, the name of the item values in Table unclear
*/
this.$refs.form.clearValidate('name');
})
Their problems with clearValidate time, select the check box has been really stubborn, input box can be removed.
replaced resetFields achieved.
Empty the contents of antd form in Form thing at the time when I went to use the clear form in the form of data antd, I found that they are not suitable jsx react assembly for use (e.g., use of the re...
Common scene All the indispensable components in all applications in the form. Recently, when using the Form component of the Element-UI, I encountered a problem that I never thought of Coding In the ...
Problem background In vue-element-ui, there is a method to clear the form, that is, if you give the form aref='form', Then the method to clear the form isthis.$refs['form'].resetFields() But when I us...
Problem Description Use the form to edit the information in the list, click the [Cancel] button to close the form and call resetFields to clear the value of the form. can be cleared for the first time...
Form verification was used in this development Use environment: After the user fills in the data, click to add, remove the content in the form, and fill in other. Question: After clicking to add, the ...
Requirement: Of course, clear form validation (ie red warning below) solve:These four ways of writing can definitely solve the problem. There is a problem: because some business scenes are mult...
Vue elementui form resetFields reset invalid Rule validation invalid Prop is essential ~ and must be consistent with the field properties! ! ! prop is essential ~ and must be consistent with the field...
to be able to query the api is resetFields (), so you might be written like this: setTimeout(() => { this.$refs['personnelForm'...
js in Custom check file elValidate.js...