mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Field): failed to reset validation when message is empty (#6867)
* fix(Field): failed to reset validation when message is empty * fix: test case
This commit is contained in:
parent
e12b468843
commit
aca86a8c21
@ -282,7 +282,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
resetValidation() {
|
resetValidation() {
|
||||||
if (this.validateMessage) {
|
if (this.validateFailed) {
|
||||||
this.validateFailed = false;
|
this.validateFailed = false;
|
||||||
this.validateMessage = '';
|
this.validateMessage = '';
|
||||||
}
|
}
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`resetValidation method - reset one field 1`] = `
|
|
||||||
<form class="van-form">
|
|
||||||
<div class="van-cell van-field">
|
|
||||||
<div class="van-cell__value van-cell__value--alone van-field__value">
|
|
||||||
<div class="van-field__body"><input type="text" name="A" class="van-field__control"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="van-cell van-field van-field--error">
|
|
||||||
<div class="van-cell__value van-cell__value--alone van-field__value">
|
|
||||||
<div class="van-field__body"><input type="text" name="B" class="van-field__control"></div>
|
|
||||||
<div class="van-field__error-message">B failed</div>
|
|
||||||
</div>
|
|
||||||
</div> <button type="submit" class="van-button van-button--default van-button--normal">
|
|
||||||
<div class="van-button__content"></div>
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
`;
|
|
@ -90,7 +90,27 @@ test('resetValidation method - reset one field', (done) => {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.$refs.form.validate().catch(() => {
|
this.$refs.form.validate().catch(() => {
|
||||||
this.$refs.form.resetValidation('A');
|
this.$refs.form.resetValidation('A');
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper.findAll('.van-field--error').length).toEqual(1);
|
||||||
|
this.$refs.form.resetValidation('B');
|
||||||
|
expect(wrapper.findAll('.van-field--error').length).toEqual(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('resetValidation method - reset when rule message is empty', (done) => {
|
||||||
|
const wrapper = mountSimpleRulesForm({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
rulesA: [{ required: true, message: '' }],
|
||||||
|
rulesB: [{ required: true, message: '' }],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$refs.form.validate().catch(() => {
|
||||||
|
this.$refs.form.resetValidation('A');
|
||||||
|
expect(wrapper.findAll('.van-field--error').length).toEqual(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user