-
-
+
+
-
+
- 校验特定字段
- 移除特定字段校验
+ 校验
+ 移除校验
+ 重置日期
@@ -37,6 +31,7 @@ import {
} from '@opentiny/vue'
const ruleFormRef = ref()
+const dateRef = ref()
const createData = reactive({
users: '',
@@ -48,7 +43,7 @@ const rules = ref({
{ required: true, message: '必填', trigger: 'blur' },
{ min: 2, max: 11, message: '长度必须不小于2', trigger: ['change', 'blur'] }
],
- datepicker: { type: 'date' },
+ datepicker: { type: 'date', required: true },
url: { type: 'url', required: true }
})
@@ -56,6 +51,10 @@ function clearValidate() {
ruleFormRef.value.clearValidate(['url', 'datepicker'])
}
+function resetField() {
+ dateRef.value.resetField()
+}
+
async function validateField() {
const errArray = []
await ruleFormRef.value.validateField(['url', 'datepicker'], (errMsg, fieldConfig) => {
@@ -64,7 +63,7 @@ async function validateField() {
}
})
if (errArray.length > 0) {
- console.log(errArray)
+ // empty
} else {
Modal.alert('日期和url通过校验')
}
diff --git a/examples/sites/demos/pc/app/form/form-validate-field.spec.ts b/examples/sites/demos/pc/app/form/form-validate-field.spec.ts
index 2a884694e..b202135d7 100644
--- a/examples/sites/demos/pc/app/form/form-validate-field.spec.ts
+++ b/examples/sites/demos/pc/app/form/form-validate-field.spec.ts
@@ -6,11 +6,18 @@ test('特定表单项校验', async ({ page }) => {
const demo = page.locator('#form-validate-field')
const getTooltipByText = (text: string) => page.locator('.tiny-tooltip').getByText(text)
+ const validBtn = demo.getByRole('button', { name: '校验' }).first()
- await demo.getByRole('button', { name: '校验特定字段' }).click()
+ await validBtn.click()
await expect(getTooltipByText('不符合规则的日期格式')).toBeVisible()
await expect(getTooltipByText('必填')).toBeVisible()
- await demo.getByRole('button', { name: '移除特定字段校验' }).click()
+ await demo.getByRole('button', { name: '移除校验' }).click()
await expect(getTooltipByText('不符合规则的日期格式')).not.toBeVisible()
await expect(getTooltipByText('必填')).not.toBeVisible()
+ await validBtn.click()
+ await expect(getTooltipByText('不符合规则的日期格式')).toBeVisible()
+ await expect(getTooltipByText('必填')).toBeVisible()
+ await demo.getByRole('button', { name: '重置日期' }).click()
+ await expect(getTooltipByText('不符合规则的日期格式')).not.toBeVisible()
+ await expect(getTooltipByText('必填')).toBeVisible()
})
diff --git a/examples/sites/demos/pc/app/form/form-validate-field.vue b/examples/sites/demos/pc/app/form/form-validate-field.vue
index 59f174c53..c2ede97fa 100644
--- a/examples/sites/demos/pc/app/form/form-validate-field.vue
+++ b/examples/sites/demos/pc/app/form/form-validate-field.vue
@@ -1,25 +1,19 @@
-
-
+
+
-
+
- 校验特定字段
- 移除特定字段校验
+ 校验
+ 移除校验
+ 重置日期
@@ -69,6 +63,9 @@ export default {
},
clearValidate() {
this.$refs.ruleFormRef.clearValidate(['url', 'datepicker'])
+ },
+ resetField() {
+ this.$refs.dateRef.resetField()
}
}
}
diff --git a/examples/sites/demos/pc/app/form/form-validation-composition-api.vue b/examples/sites/demos/pc/app/form/form-validation-composition-api.vue
index 6614dfc2b..ba5fc78a3 100644
--- a/examples/sites/demos/pc/app/form/form-validation-composition-api.vue
+++ b/examples/sites/demos/pc/app/form/form-validation-composition-api.vue
@@ -29,7 +29,8 @@
提交
- 移除校验
+ 移除校验
+ 重置表单
@@ -132,6 +133,10 @@ function handleSubmitPromise() {
function clearFormValid() {
ruleFormRef.value.clearValidate()
}
+
+function resetForm() {
+ ruleFormRef.value.resetFields()
+}