Merge pull request #1060 from Safelite/defect/CSR-1329
Added 'useField' to the button-question component so the validation v…
This commit is contained in:
commit
ba27aae0f5
5 changed files with 49 additions and 9 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
import { shallowMount, mount } from "@vue/test-utils";
|
import { shallowMount, mount } from "@vue/test-utils";
|
||||||
import buttonQuestion from "./button-question";
|
import buttonQuestion from "./button-question";
|
||||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
|
global.crypto = crypto;
|
||||||
|
|
||||||
describe("buttonQuestion.vue", () => {
|
describe("buttonQuestion.vue", () => {
|
||||||
it("Should show overflow classes on fieldset if isOverflowScrollable is true", () => {
|
it("Should show overflow classes on fieldset if isOverflowScrollable is true", () => {
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ import listButton from "@/ux-components/list-button/list-button";
|
||||||
import listButtonHorizontal from "@/ux-components/list-button-horizontal/list-button-horizontal";
|
import listButtonHorizontal from "@/ux-components/list-button-horizontal/list-button-horizontal";
|
||||||
import listCard from "@/ux-components/list-card/list-card";
|
import listCard from "@/ux-components/list-card/list-card";
|
||||||
import radio from "@/ux-components/radio/radio";
|
import radio from "@/ux-components/radio/radio";
|
||||||
import { ErrorMessage } from "vee-validate";
|
import { useField, ErrorMessage } from "vee-validate";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "buttonQuestion",
|
name: "buttonQuestion",
|
||||||
|
|
@ -128,6 +128,34 @@ export default {
|
||||||
valueToLogType: String,
|
valueToLogType: String,
|
||||||
additionalButtonStyling: String,
|
additionalButtonStyling: String,
|
||||||
isSmallQuestionText: Boolean,
|
isSmallQuestionText: Boolean,
|
||||||
|
customButtonQuestionId: String,
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
const buttonQuestionId = !props.customButtonQuestionId
|
||||||
|
? `button-question-${crypto.randomUUID()}`
|
||||||
|
: props.customButtonQuestionId;
|
||||||
|
|
||||||
|
const propsClone = Object.assign({}, props);
|
||||||
|
const modelValue = propsClone.modelValue;
|
||||||
|
|
||||||
|
const fieldOptions = {
|
||||||
|
value: modelValue,
|
||||||
|
initialValue: modelValue,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { errorMessage, handleBlur, handleChange, meta, validate, errors, resetField } =
|
||||||
|
useField(buttonQuestionId, props.validationRules, fieldOptions);
|
||||||
|
|
||||||
|
return {
|
||||||
|
buttonQuestionId,
|
||||||
|
errorMessage,
|
||||||
|
handleBlur,
|
||||||
|
handleChange,
|
||||||
|
validate,
|
||||||
|
meta,
|
||||||
|
errors,
|
||||||
|
resetField,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
if (this.buttonTypeObject) {
|
if (this.buttonTypeObject) {
|
||||||
|
|
@ -226,6 +254,11 @@ export default {
|
||||||
this.$emit(`buttonEvent.${eventName}`, event.args);
|
this.$emit(`buttonEvent.${eventName}`, event.args);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
modelValue() {
|
||||||
|
this.resetField();
|
||||||
|
},
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
listButton,
|
listButton,
|
||||||
listButtonHorizontal,
|
listButtonHorizontal,
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,15 @@
|
||||||
class="dropdown-question"
|
class="dropdown-question"
|
||||||
:class="(errors && errors.length) || hasError ? 'has-error' : ''">
|
:class="(errors && errors.length) || hasError ? 'has-error' : ''">
|
||||||
<label
|
<label
|
||||||
:for="inputId"
|
:for="dropdownId"
|
||||||
:aria-label="questionText"
|
:aria-label="questionText"
|
||||||
class="form-label"
|
class="form-label"
|
||||||
v-html="questionText"></label>
|
v-html="questionText"></label>
|
||||||
<select
|
<select
|
||||||
v-model="selectedOption"
|
v-model="selectedOption"
|
||||||
class="form-select"
|
class="form-select"
|
||||||
:id="inputId"
|
:id="dropdownId"
|
||||||
:name="inputId"
|
:name="dropdownId"
|
||||||
:aria-disabled="isDisabled"
|
:aria-disabled="isDisabled"
|
||||||
:disabled="isDisabled"
|
:disabled="isDisabled"
|
||||||
:aria-required="isRequired"
|
:aria-required="isRequired"
|
||||||
|
|
@ -46,11 +46,12 @@ export default {
|
||||||
cmsWidgetName: String,
|
cmsWidgetName: String,
|
||||||
hasError: Boolean,
|
hasError: Boolean,
|
||||||
placeHolderText: String,
|
placeHolderText: String,
|
||||||
|
customDropdownId: String,
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const inputId = !props.customInputId
|
const dropdownId = !props.customInputId
|
||||||
? `dropdown-${crypto.randomUUID()}`
|
? `dropdown-${crypto.randomUUID()}`
|
||||||
: props.customInputId;
|
: props.customDropdownId;
|
||||||
|
|
||||||
const propsClone = Object.assign({}, props);
|
const propsClone = Object.assign({}, props);
|
||||||
const modelValue = propsClone.modelValue;
|
const modelValue = propsClone.modelValue;
|
||||||
|
|
@ -72,13 +73,13 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
const { errorMessage, handleBlur, handleChange, meta, errors } = useField(
|
const { errorMessage, handleBlur, handleChange, meta, errors } = useField(
|
||||||
inputId,
|
dropdownId,
|
||||||
props.validationRules,
|
props.validationRules,
|
||||||
fieldOptions
|
fieldOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputId,
|
dropdownId,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
handleBlur,
|
handleBlur,
|
||||||
handleChange,
|
handleChange,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<transition name="fade" mode="out-in">
|
<transition name="fade" mode="out-in">
|
||||||
<div class="appointment-type-question" aria-live="polite">
|
<div class="appointment-type-question" aria-live="polite">
|
||||||
<buttonQuestion
|
<buttonQuestion
|
||||||
|
customButtonQuestionId="appointmentTypeQuestion"
|
||||||
:questionText="questionText"
|
:questionText="questionText"
|
||||||
:answers="answersToDisplay"
|
:answers="answersToDisplay"
|
||||||
:groupName="groupName"
|
:groupName="groupName"
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export default {
|
||||||
isRecalibrationServiceableMobile: null,
|
isRecalibrationServiceableMobile: null,
|
||||||
mobileFeePart: null,
|
mobileFeePart: null,
|
||||||
zipContainsMilitaryBase: false,
|
zipContainsMilitaryBase: false,
|
||||||
selectedAppointmentType: null,
|
selectedAppointmentType: "",
|
||||||
providerNumber: null,
|
providerNumber: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -198,6 +198,8 @@ export default {
|
||||||
|
|
||||||
this.state = newValue.state;
|
this.state = newValue.state;
|
||||||
this.zipCode = newValue.zipCode;
|
this.zipCode = newValue.zipCode;
|
||||||
|
|
||||||
|
this.$nextTick();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mobileLocationQuestions: {
|
mobileLocationQuestions: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue