only required field prop

pull/402/merge
Pete Matsyburka 2 months ago
parent 3e434c0878
commit ee6228db15

@ -554,14 +554,18 @@
class="flex justify-center mt-3 sm:mt-4 mb-0 sm:mb-1 select-none"
>
<div class="flex items-center flex-wrap steps-progress">
<a
<template
v-for="(step, index) in stepFields"
:key="step[0].uuid"
href="#"
class="inline border border-base-300 h-3 w-3 rounded-full mx-1 mt-1"
:class="{ 'bg-base-300 steps-progress-current': index === currentStep, 'bg-base-content': (index < currentStep && stepFields[index].every((f) => !f.required || ![null, undefined, ''].includes(values[f.uuid]))) || isCompleted, 'bg-white': index > currentStep }"
@click.prevent="isCompleted ? '' : [saveStep(), goToStep(index, true)]"
/>
>
<a
v-if="!onlyRequiredFields || step.some((f) => f.required)"
href="#"
class="inline border border-base-300 h-3 w-3 rounded-full mx-1 mt-1"
:class="{ 'bg-base-300 steps-progress-current': index === currentStep, 'bg-base-content': (index < currentStep && stepFields[index].every((f) => !f.required || ![null, undefined, ''].includes(values[f.uuid]))) || isCompleted, 'bg-white': index > currentStep }"
@click.prevent="isCompleted ? '' : [saveStep(), goToStep(index, true)]"
/>
</template>
</div>
</div>
<div
@ -693,6 +697,11 @@ export default {
required: false,
default: false
},
onlyRequiredFields: {
type: Boolean,
required: false,
default: false
},
requireSigningReason: {
type: Boolean,
required: false,
@ -955,7 +964,13 @@ export default {
submitButtonText () {
if (this.alwaysMinimize) {
return this.t('submit')
} else if (this.stepFields.length === this.currentStep + 1) {
} else if (!this.onlyRequiredFields && this.stepFields.length === this.currentStep + 1) {
if (this.currentField.type === 'signature') {
return this.t('sign_and_complete')
} else {
return this.t('complete')
}
} else if (this.onlyRequiredFields && !this.findNextStep(this.currentStep)) {
if (this.currentField.type === 'signature') {
return this.t('sign_and_complete')
} else {
@ -1174,11 +1189,11 @@ export default {
const indexesList = [this.stepFields.length - 1]
if (requiredEmptyStepIndex !== -1) {
if (requiredEmptyStepIndex !== -1 && (!this.onlyRequiredFields || this.stepFields[requiredEmptyStepIndex].some((f) => f.required))) {
indexesList.push(requiredEmptyStepIndex)
}
if (lastFilledStepIndex !== -1) {
if (lastFilledStepIndex !== -1 && (!this.onlyRequiredFields || this.stepFields[lastFilledStepIndex].some((f) => f.required))) {
indexesList.push(lastFilledStepIndex)
}
@ -1329,6 +1344,13 @@ export default {
return `${this.t('option')} ${index + 1}`
}
},
findNextStep (currentStepIndex) {
if (this.onlyRequiredFields) {
return this.stepFields.find((step, index) => index > currentStepIndex && step.some((f) => f.required))
} else {
return this.stepFields[currentStepIndex + 1]
}
},
maybeTrackEmailClick () {
const { queryParams } = this
@ -1475,7 +1497,7 @@ export default {
this.isSubmittingComplete = true
}
const submitStep = this.currentStep
const submitStepIndex = this.currentStep
const stepPromise = ['signature', 'phone', 'initials', 'payment', 'verification', 'kba'].includes(this.currentField.type)
? this.$refs.currentStep.submit
@ -1483,7 +1505,7 @@ export default {
stepPromise().then(async () => {
const emptyRequiredField = this.stepFields.find((fields, index) => {
if (forceComplete ? index === submitStep : index >= submitStep) {
if (forceComplete ? index === submitStepIndex : index >= submitStepIndex) {
return false
}
@ -1493,7 +1515,7 @@ export default {
})
const formData = new FormData(this.$refs.form)
const isLastStep = (submitStep === this.stepFields.length - 1) || forceComplete
const isLastStep = (this.onlyRequiredFields ? !this.findNextStep(submitStepIndex) : (submitStepIndex === this.stepFields.length - 1)) || forceComplete
if (isLastStep && !emptyRequiredField && !this.inviteSubmitters.length && !this.optionalInviteSubmitters.length) {
formData.append('completed', 'true')
@ -1537,7 +1559,7 @@ export default {
return Promise.reject(new Error(data.error))
}
const nextStep = (isLastStep && emptyRequiredField) || (forceComplete ? null : this.stepFields[submitStep + 1])
const nextStep = (isLastStep && emptyRequiredField) || (forceComplete ? null : this.findNextStep(submitStepIndex))
if (nextStep) {
if (this.alwaysMinimize) {

Loading…
Cancel
Save