CSR-319: add final special validation for preventSplitAndSingleTogether
This commit is contained in:
parent
7125b8182d
commit
79dca4d4bb
4 changed files with 68 additions and 10 deletions
|
|
@ -37,8 +37,8 @@
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-2 form-test-error" v-if="!suppressError">
|
<div class="row mt-2 form-test-error">
|
||||||
<error-message :name="groupName"></error-message>
|
<error-message :name="groupName" v-if="!suppressError"></error-message>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -133,6 +133,7 @@ export default {
|
||||||
if(this.isMultiSelect && this.selectedValues) {
|
if(this.isMultiSelect && this.selectedValues) {
|
||||||
// Add or remove item to array of data to emit
|
// Add or remove item to array of data to emit
|
||||||
const newSelectedValues = this.selectedValues;
|
const newSelectedValues = this.selectedValues;
|
||||||
|
|
||||||
if(Array.isArray(this.selectedValues)) {
|
if(Array.isArray(this.selectedValues)) {
|
||||||
val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1);
|
val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1);
|
||||||
this.selectedValues = newSelectedValues;
|
this.selectedValues = newSelectedValues;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
buttonType="listCard"
|
buttonType="listCard"
|
||||||
v-model="selectedValues"
|
v-model="selectedValues"
|
||||||
:validationRules="validationRules"
|
:validationRules="validationRules"
|
||||||
|
:suppressError="suppressError"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
|
@ -35,6 +36,7 @@ export default ({
|
||||||
modelValue: Array,
|
modelValue: Array,
|
||||||
isMultiSelect: Boolean,
|
isMultiSelect: Boolean,
|
||||||
validationRules: String,
|
validationRules: String,
|
||||||
|
suppressError: Boolean,
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initializeComponent(cmsContent, replaceOptions){
|
initializeComponent(cmsContent, replaceOptions){
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
ref="windshieldOptions"
|
ref="windshieldOptions"
|
||||||
v-model="selectedWindshieldOptions"
|
v-model="selectedWindshieldOptions"
|
||||||
:hasRepairReplaceConflict="hasRepairReplaceConflict"
|
:hasRepairReplaceConflict="hasRepairReplaceConflict"
|
||||||
|
:hasSplitSingleConflict="hasSplitSingleConflict"
|
||||||
:selectedDamageLocations="selectedDamageLocations"
|
:selectedDamageLocations="selectedDamageLocations"
|
||||||
/>
|
/>
|
||||||
<alert
|
<alert
|
||||||
|
|
@ -392,6 +393,23 @@ export default {
|
||||||
hasRepairReplaceConflict() {
|
hasRepairReplaceConflict() {
|
||||||
return this.isWindshieldDamageLocation && this.selectedDamageLocations.length > 1 && this.isWindshieldRepair;
|
return this.isWindshieldDamageLocation && this.selectedDamageLocations.length > 1 && this.isWindshieldRepair;
|
||||||
},
|
},
|
||||||
|
hasSplitSingleConflict() {
|
||||||
|
if (!this.selectedWindshieldOptions.selectedWindshieldReplaceOptions) return false;
|
||||||
|
|
||||||
|
return this.selectedWindshieldOptions.selectedWindshieldReplaceOptions.some(selectedSingleWindshield =>
|
||||||
|
{
|
||||||
|
return selectedSingleWindshield.toUpperCase() === damageLocationsSelected.SINGLE.toUpperCase();
|
||||||
|
}) &&
|
||||||
|
(this.selectedWindshieldOptions.selectedWindshieldReplaceOptions.some(selectedDriverWindshield =>
|
||||||
|
{
|
||||||
|
return selectedDriverWindshield.toUpperCase() === damageLocationsSelected.DRIVER.toUpperCase();
|
||||||
|
}) ||
|
||||||
|
this.selectedWindshieldOptions.selectedWindshieldReplaceOptions.some(selectedPassengerWindshield =>
|
||||||
|
{
|
||||||
|
return selectedPassengerWindshield.toUpperCase() === damageLocationsSelected.PASSENGER.toUpperCase();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,17 @@
|
||||||
<div class="windshield-options">
|
<div class="windshield-options">
|
||||||
<windshieldDamageTypeQuestion ref="windshieldDamageTypeQuestion"
|
<windshieldDamageTypeQuestion ref="windshieldDamageTypeQuestion"
|
||||||
:isAvailable=isWindshieldDamageLocation
|
:isAvailable=isWindshieldDamageLocation
|
||||||
:suppressError="hasRepairReplaceConflict || showNoReplaceAvailableError"
|
:suppressError="hasRepairReplaceConflict || showNoReplacementAvailableError"
|
||||||
groupName="WindshieldDamageTypeQuestion"
|
groupName="WindshieldDamageTypeQuestion"
|
||||||
v-model="selectedWindshieldDamageTypeValues"
|
v-model="selectedWindshieldDamageTypeValues"
|
||||||
:validationRules="isWindshieldReplaceAvailable ? 'windshield-damage-type-required|checkForRepairAndReplace:@DamageLocationQuestion' : 'windshield-damage-type-required|checkForRepairAndReplace:@DamageLocationQuestion|repairOnly'"
|
:validationRules="windshieldDamageTypeQuestionValidationRules"
|
||||||
/>
|
/>
|
||||||
|
isSplitWindshieldOption: {{isSplitWindshieldOption}}
|
||||||
|
<hr>
|
||||||
|
isWindshieldReplaceAvailable: {{isWindshieldReplaceAvailable}}
|
||||||
<alert
|
<alert
|
||||||
class="my-3"
|
class="my-3"
|
||||||
v-show="showNoReplaceAvailableError"
|
v-show="showNoReplacementAvailableError"
|
||||||
alertClass="alert-danger"
|
alertClass="alert-danger"
|
||||||
alertHeadline="Service not available"
|
alertHeadline="Service not available"
|
||||||
alertCopy="We're sorry, but we currently offer only repair service for your vehicle type. Need help with next steps? Call us at 800-394-0288."
|
alertCopy="We're sorry, but we currently offer only repair service for your vehicle type. Need help with next steps? Call us at 800-394-0288."
|
||||||
|
|
@ -26,8 +29,17 @@
|
||||||
isMultiSelect
|
isMultiSelect
|
||||||
groupName="WindshieldReplaceOptions"
|
groupName="WindshieldReplaceOptions"
|
||||||
v-model="selectedWindshieldReplaceOptionsValues"
|
v-model="selectedWindshieldReplaceOptionsValues"
|
||||||
validationRules="windshield-replace-options-required"
|
validationRules="windshield-replace-options-required|preventSplitAndSingleTogether"
|
||||||
|
:suppressError="hasSplitSingleConflict"
|
||||||
/>
|
/>
|
||||||
|
<alert
|
||||||
|
class="my-3"
|
||||||
|
v-show="hasSplitSingleConflict"
|
||||||
|
alertClass="alert-danger"
|
||||||
|
alertHeadline="Single-piece or split?"
|
||||||
|
alertCopy="Please select just one windshield option: single-piece or split."
|
||||||
|
:isDismissible="false"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -53,17 +65,25 @@ defineRule("checkForRepairAndReplace", (value, [otherFieldValue]) => {
|
||||||
Array.isArray(otherFieldValue) &&
|
Array.isArray(otherFieldValue) &&
|
||||||
otherFieldValue.length > 1)
|
otherFieldValue.length > 1)
|
||||||
{
|
{
|
||||||
return "checkForRepairAndReplace error"
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
defineRule("repairOnly", (value) => {
|
defineRule("repairOnly", (value) => {
|
||||||
if (value.toString().toUpperCase() === damageLocationsSelected.REPAIR.toUpperCase()) {
|
if (value.toString().toUpperCase() === damageLocationsSelected.REPAIR.toUpperCase()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
defineRule("preventSplitAndSingleTogether", (value) => {
|
||||||
|
if (value.toString().toUpperCase().includes(damageLocationsSelected.SINGLE.toUpperCase()) &&
|
||||||
|
(value.toString().toUpperCase().includes(damageLocationsSelected.DRIVER.toUpperCase()) ||
|
||||||
|
value.toString().toUpperCase().includes(damageLocationsSelected.PASSENGER.toUpperCase())))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
export default ({
|
export default ({
|
||||||
name: "windshieldOptions",
|
name: "windshieldOptions",
|
||||||
|
|
@ -77,7 +97,8 @@ export default ({
|
||||||
props: {
|
props: {
|
||||||
modelValue: Array,
|
modelValue: Array,
|
||||||
selectedDamageLocations: Array,
|
selectedDamageLocations: Array,
|
||||||
hasRepairReplaceConflict: Boolean
|
hasRepairReplaceConflict: Boolean,
|
||||||
|
hasSplitSingleConflict: Boolean,
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -151,12 +172,28 @@ export default ({
|
||||||
isWindshieldReplaceAvailable() {
|
isWindshieldReplaceAvailable() {
|
||||||
return !(Array.isArray(this.windshieldAvailableReplacementOptions) && this.windshieldAvailableReplacementOptions.length < 1);
|
return !(Array.isArray(this.windshieldAvailableReplacementOptions) && this.windshieldAvailableReplacementOptions.length < 1);
|
||||||
},
|
},
|
||||||
showNoReplaceAvailableError() {
|
isSplitWindshieldOption() {
|
||||||
|
const options = this.windshieldAvailableReplacementOptions.toString().toUpperCase();
|
||||||
|
if (options.includes('DRIVER') && options.includes('PASSENGER')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
showNoReplacementAvailableError() {
|
||||||
if (this.isReplaceOptionSelected && !this.isWindshieldReplaceAvailable) {
|
if (this.isReplaceOptionSelected && !this.isWindshieldReplaceAvailable) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
windshieldDamageTypeQuestionValidationRules() {
|
||||||
|
// Note: the validation rules string is not dynamic (it cannot be changed once component has been created)
|
||||||
|
let validationRules = "windshield-damage-type-required|checkForRepairAndReplace:@DamageLocationQuestion";
|
||||||
|
// if vehicle has no windshield replacement option
|
||||||
|
if (!this.isWindshieldReplaceAvailable) {
|
||||||
|
validationRules = validationRules.concat('|repairOnly');
|
||||||
|
}
|
||||||
|
return validationRules;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
windshieldDamageTypeQuestion,
|
windshieldDamageTypeQuestion,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue