-
I have a form that has a normal save method which validates and saves with validation errors blocking submissions. But, I need a submission that is Save as Draft that bypasses the validation and submits with errors. The normal save and validate is working great, but I can't seem to find a way to easily turn off validation dynamically. This is the stripped down version of what I have right now
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
After lots of digging and some minor refactoring I was able to get this working. The key was changing from field based rules and validation to form based since the My setup script now looks like the following: import { useForm } from "vee-validate";
import { computed, reactive } from "vue";
const submissionValidation = {
'consult_patient_name': 'required|min:5',
'item_name': 'required|min:2',
'consult_question': 'required|min:5',
'consult_history': 'required|min:5',
};
// if it's a draft set it to false, so it can bypass validation
// otherwise set it to the actual validation schema
const validationSchema = computed(() =>
item.draft === true
? false
: submissionValidation
);
const { handleSubmit, isSubmitting } = useForm({ validationSchema });
const item = reactive({
draft: false
});
const saveForm = handleSubmit(async () => {
// do stuff to save here
}) |
Beta Was this translation helpful? Give feedback.
After lots of digging and some minor refactoring I was able to get this working. The key was changing from field based rules and validation to form based since the
validationSchema
is reactive. Then I can just change the schema tofalse
to make the form skip validation when it's a draft.My setup script now looks like the following: