js
VeeValidate.Validator.extend('requireWithoutAll', {
validate: (value, [ ...target ]) => {
return value && _.compact(target).length;
},
getMessage: (field, [...target]) => 'The ${field} is required when none of ${target} are present.'
}, {
hasTarget: true
});
전망
<ValidationProvider name="name1" vid="ref1">
<el-form-item slot-scope="{ errors }" :error="errors[0]" label="Lorum Ipsum 1">
<el-checkbox v-model="is_model_1">Yes</el-checkbox>
</el-form-item>
</ValidationProvider>
<ValidationProvider name="name2" vid="ref2">
<el-form-item slot-scope="{ errors }" :error="errors[0]" label="Lorum Ipsum 2">
<el-checkbox v-model="is_model_2">Yes</el-checkbox>
</el-form-item>
</ValidationProvider>
<ValidationProvider :rules="'requireWithoutAll:ref1,ref2'" name="name3" vid="ref3">
<el-form-item slot-scope="{ errors }" :error="errors[0]" label="Lorum Ipsum 3">
<el-checkbox v-model="is_model_3">Yes</el-checkbox>
</el-form-item>
</ValidationProvider>
결과를 예상 하는 경우 ref1
및 ref2
선택되지 않습니다에 발생하는 오류가 ref3
.
실제 결과 오류가 생성되지 않습니다.
대상을 지정하는 형식은 rules="requireWithoutAll:@ref1,@ref2"
아닙니다 rules="requireWithoutAll:ref1,ref2"
.
https://codesandbox.io/s/codesandbox-forked-u0s3g?file=/src/Demo.vue 에서 작동하는 예를 참조하십시오.
관련 코드 :
<ValidationProvider
rules="requireWithoutAll:@ref1,@ref2"
vid="ref3"
v-slot="{ errors }"
tag="div"
>
<!-- your checkbox UI here -->
</ValidationProvider>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다