Removed semiAggressiveValidation property and conditional in watch statement
This commit is contained in:
parent
7f59c31c54
commit
cb9fc0a4e4
8 changed files with 5 additions and 121 deletions
|
|
@ -1,35 +0,0 @@
|
||||||
import { shallowMount } from "@vue/test-utils";
|
|
||||||
import textInput from "./text-input";
|
|
||||||
|
|
||||||
describe("text-input.vue", () => {
|
|
||||||
it("Should render a text input", async () => {
|
|
||||||
// Act
|
|
||||||
const wrapper = shallowMount(textInput, {
|
|
||||||
propsData: {
|
|
||||||
name: "test",
|
|
||||||
label: "unit test label",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
const input = wrapper.find("input");
|
|
||||||
|
|
||||||
expect(input.exists()).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should return aria-required state", async () => {
|
|
||||||
// Act
|
|
||||||
const wrapper = shallowMount(textInput, {
|
|
||||||
propsData: {
|
|
||||||
name: "test",
|
|
||||||
label: "unit test label",
|
|
||||||
isRequired: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
const input = wrapper.find("input");
|
|
||||||
|
|
||||||
expect(input.attributes()["aria-required"]).toEqual("true");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
<!-- Simple implementation of an input field -->
|
|
||||||
<template>
|
|
||||||
<div class="d-flex w-50 mb-2" :class="{ 'has-error': !!errorMessage }">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
:name="name"
|
|
||||||
:value="inputValue"
|
|
||||||
:id="name"
|
|
||||||
:aria-required="isRequired"
|
|
||||||
@input="handleChange"
|
|
||||||
@blur="handleBlur"
|
|
||||||
:data-focus-target="name"
|
|
||||||
/>
|
|
||||||
<label
|
|
||||||
:for="name"
|
|
||||||
:aria-labelledby="name"
|
|
||||||
class="d-flex justify-content-center py-3 px-4"
|
|
||||||
>
|
|
||||||
<span class="m-0">{{ label }}</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div v-show="errorMessage" class="row px-3 form-test-error">
|
|
||||||
{{ errorMessage }}
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { useField } from "vee-validate";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: "textInput",
|
|
||||||
props: {
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
default: "text",
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
type: String,
|
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
isRequired: Boolean,
|
|
||||||
},
|
|
||||||
setup(props) {
|
|
||||||
const {
|
|
||||||
value: inputValue,
|
|
||||||
errorMessage,
|
|
||||||
handleBlur,
|
|
||||||
handleChange,
|
|
||||||
meta,
|
|
||||||
} = useField(props.name, undefined, {
|
|
||||||
initialValue: props.value,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
handleChange,
|
|
||||||
handleBlur,
|
|
||||||
errorMessage,
|
|
||||||
inputValue,
|
|
||||||
meta,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
@ -167,7 +167,7 @@ describe("textboxQuestion.vue", () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should call this.handleChange with new value when this.semiAggressiveValidation = true, the value is changed, and the new value is valid", async () => {
|
it("Should call this.handleChange with new value when the value is changed and the new value is valid", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const wrapper = shallowMount(textboxQuestion, {
|
const wrapper = shallowMount(textboxQuestion, {
|
||||||
global: {
|
global: {
|
||||||
|
|
@ -178,7 +178,6 @@ describe("textboxQuestion.vue", () => {
|
||||||
propsData: {
|
propsData: {
|
||||||
options: {},
|
options: {},
|
||||||
modelValue: "foo",
|
modelValue: "foo",
|
||||||
semiAggressiveValidation: true,
|
|
||||||
},
|
},
|
||||||
mixins: [mockMixin]
|
mixins: [mockMixin]
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ export default {
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
validationRules: String,
|
validationRules: String,
|
||||||
semiAggressiveValidation: Boolean,
|
|
||||||
cmsWidgetName: String,
|
cmsWidgetName: String,
|
||||||
maxLength: String,
|
maxLength: String,
|
||||||
},
|
},
|
||||||
|
|
@ -130,12 +129,10 @@ export default {
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
async value(newValue) {
|
async value(newValue) {
|
||||||
if (this.semiAggressiveValidation) {
|
const result = await validate(newValue, this.validationRules); // do a test validation check, without triggering full validation
|
||||||
const result = await validate(newValue, this.validationRules); // do a test validation check, without triggering full validation
|
if (result.valid) {
|
||||||
if (result.valid) {
|
this.handleChange(newValue); // trigger full validation on this field only
|
||||||
this.handleChange(newValue); // trigger full validation on this field only
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
inputId="cbf28188fdf2436688fd735915f7ee56"
|
inputId="cbf28188fdf2436688fd735915f7ee56"
|
||||||
disableAutoFill
|
disableAutoFill
|
||||||
validationRules="city-required"
|
validationRules="city-required"
|
||||||
semiAggressiveValidation
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -52,7 +51,6 @@
|
||||||
mask="#####"
|
mask="#####"
|
||||||
disableAutoFill
|
disableAutoFill
|
||||||
validationRules="zip-code-required|zip-code-format"
|
validationRules="zip-code-required|zip-code-format"
|
||||||
semiAggressiveValidation
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@
|
||||||
inputId="00450a91b8964a768ce3992e6feb890f"
|
inputId="00450a91b8964a768ce3992e6feb890f"
|
||||||
disableAutoFill
|
disableAutoFill
|
||||||
validationRules="email-address-required|email-address-format"
|
validationRules="email-address-required|email-address-format"
|
||||||
semiAggressiveValidation
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@
|
||||||
v-model="email"
|
v-model="email"
|
||||||
inputId="email"
|
inputId="email"
|
||||||
validationRules="email-address-required|email-address-format"
|
validationRules="email-address-required|email-address-format"
|
||||||
semiAggressiveValidation
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -54,7 +53,6 @@
|
||||||
v-model="serviceZip"
|
v-model="serviceZip"
|
||||||
inputId="serviceZip"
|
inputId="serviceZip"
|
||||||
validationRules="zip-required|zip-format"
|
validationRules="zip-required|zip-format"
|
||||||
semiAggressiveValidation
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,6 @@
|
||||||
isRequired
|
isRequired
|
||||||
disableAutoFill
|
disableAutoFill
|
||||||
validationRules="email-address-required|email-address-format"
|
validationRules="email-address-required|email-address-format"
|
||||||
semiAggressiveValidation
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue