Moved 'useForm' inside modal component

This commit is contained in:
Leah Schumann 2023-02-14 07:46:29 -05:00
parent bfed75f7b4
commit b6f70b9b86
4 changed files with 32 additions and 47 deletions

View file

@ -43,7 +43,7 @@
<script> <script>
import buttonMain from "@/ux-components/button-main/button-main"; import buttonMain from "@/ux-components/button-main/button-main";
import { Modal } from "bootstrap"; import { Modal } from "bootstrap";
import { useIsFormTouched, useIsFormDirty, useIsFormValid } from "vee-validate"; import { useForm, useIsFormTouched, useIsFormDirty, useIsFormValid } from "vee-validate";
export default { export default {
name: "modal", name: "modal",
@ -60,15 +60,17 @@ export default {
setup() { setup() {
const modalId = `modal-${crypto.randomUUID()}`; const modalId = `modal-${crypto.randomUUID()}`;
const isTouched = useIsFormTouched(); const form = useForm();
const isDirty = useIsFormDirty(); const isFormTouched = useIsFormTouched();
const isValid = useIsFormValid(); const isFormDirty = useIsFormDirty();
const isFormValid = useIsFormValid();
return { return {
modalId, modalId,
isTouched, form,
isDirty, isFormTouched,
isValid, isFormDirty,
isFormValid,
}; };
}, },
methods: { methods: {
@ -99,10 +101,10 @@ export default {
}, },
computed: { computed: {
isFooterButtonDisabled() { isFooterButtonDisabled() {
if (!this.isTouched) { if (!this.isFormTouched) {
return !this.isValid; return !this.isFormValid;
} }
return !this.isDirty || !this.isValid; return !this.isFormDirty || !this.isFormValid;
}, },
}, },
components: { components: {

View file

@ -20,7 +20,7 @@
<modal <modal
:ref="modalName" :ref="modalName"
:headerText="modalHeaderText" :headerText="modalHeaderText"
:onModalOpenedCallback="onModalOpened" :onModalClosedCallback="onModalClosed"
:footerButtonText="modalFooterText" :footerButtonText="modalFooterText"
@footer-button-event="setMobileLocation"> @footer-button-event="setMobileLocation">
<addressQuestions <addressQuestions
@ -44,11 +44,6 @@ import addressQuestions from "@/layouts/address-lookup/customer-questions/addres
import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location-modal-questions/vehicle-protected-question/vehicle-protected-question"; import vehicleProtectedQuestion from "@/layouts/service-location/mobile-location-modal-questions/vehicle-protected-question/vehicle-protected-question";
import textBlock from "@/digital-components/text-block/text-block"; import textBlock from "@/digital-components/text-block/text-block";
// Supporting Files
import { useForm } from "vee-validate";
// Define Validation Rules
export default { export default {
name: "mobile-location-modal-questions", name: "mobile-location-modal-questions",
emits: ["update:modelValue"], // The component emits an event emits: ["update:modelValue"], // The component emits an event
@ -68,13 +63,6 @@ export default {
}, },
}; };
}, },
setup() {
const modalForm = useForm();
return {
modalForm,
};
},
props: { props: {
modelValue: { modelValue: {
type: Object, type: Object,
@ -135,6 +123,11 @@ export default {
}, },
}, },
addressModel: { addressModel: {
get: function () {
return this.mobileLocationQuestionsModel.addressQuestions;
},
},
addressModelInput: {
get: function () { get: function () {
return this.mobileLocationQuestionsInput.addressQuestions; return this.mobileLocationQuestionsInput.addressQuestions;
}, },
@ -144,12 +137,15 @@ export default {
openModal() { openModal() {
this.$refs[this.modalName].openModal(); this.$refs[this.modalName].openModal();
}, },
onModalClosed() { onModalOpened() {
this.mobileLocationQuestionsInput = this.mobileLocationQuestionsModel; this.mobileLocationQuestionsInput = this.mobileLocationQuestionsModel;
}, },
closeModal() { closeModal() {
this.$refs[this.modalName].closeModal(); this.$refs[this.modalName].closeModal();
}, },
onModalClosed() {
this.mobileLocationQuestionsInput = this.mobileLocationQuestionsModel;
},
resetModel() { resetModel() {
// Address // Address
this.addressModel.streetAddress = ""; this.addressModel.streetAddress = "";
@ -164,11 +160,12 @@ export default {
async setMobileLocation() { async setMobileLocation() {
this.mobileLocationQuestionsModel = { this.mobileLocationQuestionsModel = {
addressQuestions: { addressQuestions: {
streetAddress: this.addressModel.streetAddress, streetAddress: this.addressModelInput.streetAddress,
apartmentNumberOrBusinessName: this.addressModel.apartmentNumberOrBusinessName, apartmentNumberOrBusinessName:
city: this.addressModel.city, this.addressModelInput.apartmentNumberOrBusinessName,
state: this.addressModel.state, city: this.addressModelInput.city,
zipCode: this.addressModel.zipCode, state: this.addressModelInput.state,
zipCode: this.addressModelInput.zipCode,
}, },
isVehicleProtected: this.mobileLocationQuestionsInput.isVehicleProtected, isVehicleProtected: this.mobileLocationQuestionsInput.isVehicleProtected,
isZipServiceableMobile: this.mobileLocationQuestionsInput.isZipServiceableMobile, isZipServiceableMobile: this.mobileLocationQuestionsInput.isZipServiceableMobile,
@ -178,14 +175,6 @@ export default {
this.closeModal(); this.closeModal();
}, },
}, },
watch: {
serviceZipCode: {
handler() {
// if they modify the Service Zip Code, clear the model
this.resetModel();
},
},
},
components: { components: {
textLink, textLink,
modal, modal,

View file

@ -100,11 +100,12 @@ export default {
isVehicleProtected: this.isVehicleProtected, isVehicleProtected: this.isVehicleProtected,
isZipServiceableMobile: this.isZipServiceableMobile, isZipServiceableMobile: this.isZipServiceableMobile,
isZipServiceableInShop: this.isZipServiceableInShop, isZipServiceableInShop: this.isZipServiceableInShop,
} };
}, },
set: function (newValue) { set: function (newValue) {
this.streetAddress = newValue.addressQuestions.streetAddress; this.streetAddress = newValue.addressQuestions.streetAddress;
this.apartmentNumberOrBusinessName = newValue.addressQuestions.apartmentNumberOrBusinessName; this.apartmentNumberOrBusinessName =
newValue.addressQuestions.apartmentNumberOrBusinessName;
this.city = newValue.addressQuestions.city; this.city = newValue.addressQuestions.city;
this.state = newValue.addressQuestions.state; this.state = newValue.addressQuestions.state;
this.zipCode = newValue.addressQuestions.zipCode; this.zipCode = newValue.addressQuestions.zipCode;

View file

@ -71,13 +71,6 @@ export default {
textboxQuestionWidgetName: String, textboxQuestionWidgetName: String,
alertInvalidZipWidgetName: String, alertInvalidZipWidgetName: String,
}, },
setup() {
const modalForm = useForm();
return {
modalForm,
};
},
computed: { computed: {
serviceZipLinkText() { serviceZipLinkText() {
if (this.modelValue.zipCode && this.modelValue.zipCode.length > 0) { if (this.modelValue.zipCode && this.modelValue.zipCode.length > 0) {