Skip to content
Merged

Dev #59

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/plugin/VStepperForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,25 @@ function removePageError(pageIndex: number): void {
currentPageHasErrors.value = false;
}

// Reset the next page fields //
const resetPageFields = (pageIndex: number) => {
const page = computedPages.value[pageIndex + 1];

if (!page) {
return;
}

if (!page?.fields?.length) {
return;
}

for (const field of page.fields) {
if (field.name) {
$useForm.resetField(field.name, { force: true });
}
}
};

// ------------------------ Check the if the page has errors //
function checkForPageErrors(errors: ValidateResult['errors'], source: string, next = () => { }): void {
const page = computedPages.value[currentPageIdx.value];
Expand All @@ -553,6 +572,7 @@ function checkForPageErrors(errors: ValidateResult['errors'], source: string, ne
removePageError(pageIndex);

if (next && !lastPage.value && source !== 'submit') {
resetPageFields(pageIndex);
next();
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/plugin/components/fields/VSFCustom/VSFCustom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const settings = inject<Ref<Settings>>('settings')!;

const FieldLabelComponent = toRaw(FieldLabel);
const fieldValidateOn = computed(() => field.value?.validateOn ?? settings.value.validateOn);
const originalValue = modelValue.value;


const $useField = useField(
Expand All @@ -61,6 +62,13 @@ const $useField = useField(
},
);

onUnmounted(() => {
if (!settings.value.keepValuesOnUnmount) {
modelValue.value = originalValue;
$useField.setValue(originalValue);
}
});


// ------------------------- Validate On Actions //
async function onActions(action: ValidateAction): Promise<void> {
Expand Down