From 99e0b297b21f0c482bcc0eecd4c68d24ac5fffd9 Mon Sep 17 00:00:00 2001 From: James Collins Date: Tue, 18 Apr 2023 11:29:38 +1000 Subject: [PATCH] added change emitter --- resources/js/components/SMInput.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/resources/js/components/SMInput.vue b/resources/js/components/SMInput.vue index a4cd58c..5f87239 100644 --- a/resources/js/components/SMInput.vue +++ b/resources/js/components/SMInput.vue @@ -50,7 +50,7 @@ import { inject, watch, ref, useSlots } from "vue"; import { isEmpty } from "../helpers/utils"; import { toTitleCase } from "../helpers/string"; -const emits = defineEmits(["update:modelValue"]); +const emits = defineEmits(["update:modelValue", "change"]); const props = defineProps({ form: { type: Object, @@ -133,12 +133,15 @@ const id = ref( : "" ); const feedbackInvalid = ref(""); -const active = ref(value.value != ""); +const active = ref(value.value.length > 0); const disabled = ref(props.disabled); -watch(value, (newValue) => { - active.value = newValue.value != ""; -}); +watch( + () => value.value, + (newValue) => { + active.value = newValue.length > 0; + } +); if (typeof control === "object" && control !== null) { watch( @@ -161,7 +164,6 @@ if (typeof control === "object" && control !== null) { } if (form) { - console.log("here form"); watch( () => form.loading(), (newValue) => { @@ -196,6 +198,8 @@ const handleInput = (event: Event) => { const handleClear = () => { value.value = ""; + emits("update:modelValue", ""); + emits("change"); };