Merge pull request #1247 from Safelite/defect/CSR-1485

Add error validation to date-picker
This commit is contained in:
chloeherdsafelite 2023-07-18 09:24:57 -04:00 committed by GitHub
commit 04f36bc290
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View file

@ -56,6 +56,9 @@
:class="[!isLoading ? 'date-picker-hidden' : '']" :class="[!isLoading ? 'date-picker-hidden' : '']"
loaderColor="blue" loaderColor="blue"
loaderPosition="center" /> loaderPosition="center" />
<div class="row form-test-error">
<ErrorMessage name="date-of-month" class="small mt-1"></ErrorMessage>
</div>
<button <button
v-if="calendarViewDirection === 'future' && !disableViewMoreDatesButton" v-if="calendarViewDirection === 'future' && !disableViewMoreDatesButton"
type="button" type="button"
@ -79,6 +82,7 @@ import {
convertDateToDateString, convertDateToDateString,
convertDateStringToDate, convertDateStringToDate,
} from "@/layouts/schedule/helpers/schedule-helper"; } from "@/layouts/schedule/helpers/schedule-helper";
import { useField, ErrorMessage } from "vee-validate";
export default { export default {
name: "datePicker", name: "datePicker",
@ -113,6 +117,32 @@ export default {
return []; return [];
}, },
}, },
validationRules: {
type: String,
default: "",
},
},
setup(props) {
const propsClone = Object.assign({}, props);
const modelValue = propsClone.modelValue;
const fieldOptions = {
value: modelValue,
initialValue: modelValue,
};
const { errorMessage, handleBlur, handleChange, meta, validate, errors, resetField } =
useField("date-of-month", props.validationRules, fieldOptions);
return {
errorMessage,
handleBlur,
handleChange,
validate,
meta,
errors,
resetField,
};
}, },
computed: { computed: {
todayString() { todayString() {
@ -639,8 +669,16 @@ export default {
window.requestAnimationFrame(step); window.requestAnimationFrame(step);
}, },
}, },
watch: {
modelValue(newValue, oldValue) {
this.resetField({
value: newValue,
});
},
},
components: { components: {
loader, loader,
ErrorMessage,
}, },
}; };
</script> </script>
@ -979,4 +1017,10 @@ export default {
text-underline-offset: 4px; text-underline-offset: 4px;
z-index: 2; z-index: 2;
} }
.form-test-error {
margin: 0 auto 2rem auto;
max-width: 414px;
text-align: left;
}
</style> </style>

View file

@ -18,6 +18,7 @@
v-model="selectedDate" v-model="selectedDate"
class="text-link-small" class="text-link-small"
:customSelectableDatesCallback="getAvailableDatesMethod" :customSelectableDatesCallback="getAvailableDatesMethod"
validationRules="date-required"
@date-clicked="openInshopTimeSlotsModal" /> @date-clicked="openInshopTimeSlotsModal" />
<time-slot-modal-question <time-slot-modal-question
ref="timeSlotModalQuestion" ref="timeSlotModalQuestion"