Suggestletdisabled=ref(true);leterror=ref(false);nextTick(()=>">
I want to disable the form submit button until all input fields are filled in and there are no errors.
let disabled = ref(true); let error = ref(false); nextTick(() => { let inputs = Array.from(document.getElementsByClassName("form__input")); if (!error.value) { inputs.forEach((input) => { if (input.value === "") { disabled.value = true; } else { disabled.value = false; } }); } })
The button is disabled by default, but it will not "enable" itself once the conditions already mentioned are met.
So far I'm using a secondary lifecycle hooknextTick()
which obviously doesn't help me in this case.
The "disabled" status will be updated in the console, but not on the DOM.
How can I solve this problem?
cheers
Maybe you should use
v-model
,compulated
or@input
to listen to events and change the button disabled state.The simplest solution is to set the disabled state of the button using a
calculated
value - based on the input value - if any are empty, the button is disabledThis is a basic example
. . . . test