From 7c4f377e2b50cb3e0b1d80b3558bea679a0fac44 Mon Sep 17 00:00:00 2001 From: James Collins Date: Mon, 20 Feb 2023 18:42:26 +1000 Subject: [PATCH] update value when control value changes --- resources/js/components/SMInput.vue | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/resources/js/components/SMInput.vue b/resources/js/components/SMInput.vue index ba37575..7020d71 100644 --- a/resources/js/components/SMInput.vue +++ b/resources/js/components/SMInput.vue @@ -155,6 +155,8 @@ const objControl = const label = ref(props.label); const feedbackInvalid = ref(props.feedbackInvalid); +const value = ref(props.modelValue); +const inputActive = ref(value.value.length > 0 || props.type == "select"); watch( () => props.label, @@ -163,7 +165,6 @@ watch( } ); -const value = ref(props.modelValue); if (objControl) { if (value.value.length > 0) { objControl.value = value.value; @@ -184,6 +185,14 @@ if (objControl) { }, { deep: true } ); + + watch( + () => objControl.value, + (newValue) => { + value.value = newValue; + }, + { deep: true } + ); } watch( @@ -200,7 +209,12 @@ watch( } ); -const inputActive = ref(value.value.length > 0 || props.type == "select"); +watch( + () => value.value, + (newValue) => { + inputActive.value = newValue.length > 0; + } +); const handleChange = (event) => { emits("update:modelValue", event.target.files[0]);