Validation working

This commit is contained in:
Chloe Herd 2024-07-09 10:07:15 -04:00
parent f9fea3c9b6
commit 2beb9407d3

View file

@ -9,9 +9,9 @@
class="form-check-input me-2" class="form-check-input me-2"
type="checkbox" type="checkbox"
aria-checked="false" aria-checked="false"
:name="checkboxName" :name="inputId"
:validationRules="validationRules" :validationRules="validationRules"
:id="buttonID" :id="inputId"
:tabindex="tabIndex" :tabindex="tabIndex"
:aria-required="isRequired" /> :aria-required="isRequired" />
<p v-html="checkboxLabelCopy" class="m-0"></p> <p v-html="checkboxLabelCopy" class="m-0"></p>
@ -30,31 +30,28 @@ export default {
checkboxLabelCopy() { checkboxLabelCopy() {
return this.getCmsContent(this.cmsWidgetName, "QuestionText"); return this.getCmsContent(this.cmsWidgetName, "QuestionText");
}, },
value: {
get: function () {
return this.modelValue;
},
set: function (newValue) {
this.$emit("update:modelValue", newValue);
},
},
}, },
setup(props) { setup(props) {
const uuid = uuidv4(); const uuid = uuidv4();
const inputId = !props.customInputId ? `input-${uuid}` : props.customInputId; const inputId = !props.customInputId ? `input-${uuid}` : props.customInputId;
const propsClone = Object.assign({}, props);
const modelValue = propsClone.modelValue;
const fieldOptions = { const fieldOptions = {
value: modelValue, initialValue: props.modelValue,
initialValue: null,
}; };
const { errorMessage, handleBlur, handleChange, meta, validate, errors, resetField } = const {
useField(inputId, props.validationRules, fieldOptions); value,
errorMessage,
handleBlur,
handleChange,
meta,
validate,
errors,
resetField,
} = useField(inputId, props.validationRules, fieldOptions);
return { return {
value,
errorMessage, errorMessage,
handleBlur, handleBlur,
handleChange, handleChange,
@ -79,6 +76,16 @@ export default {
default: false, default: false,
}, },
}, },
watch: {
modelValue(newValue, oldValue) {
if (this.value !== newValue) {
this.value = newValue;
}
},
value(newValue, oldValue) {
this.$emit("update:modelValue", newValue);
},
},
}; };
</script> </script>