When using Vue Formulate, the schema itself is designed to be reactive. To implement conditional fields using a schema, the recommended approach is to pass the schema through a computed property first. Here's an example:
<template>
<FormulateForm
v-model="formValues"
:schema="conditionalSchema"
/>
</template>
<script>
const schema = [
{
type: "radio",
options: { a: 'A', b: 'B' },
label: 'Do you like a or b?',
name: 'question',
id: 'question'
},
{
type: 'text',
name: 'c',
id: 'c',
label: 'If you like b, then you must like c!'
}
]
export default {
data () {
return {
formValues: {}
}
},
computed: {
conditionalSchema() {
if (this.formValues.question !== 'b') {
return schema.filter(({ name }) => name !== 'c')
}
return schema
}
}
}
</script>
Feel free to check out the code on CodePen: https://codepen.io/justin-schroeder/pen/dyXPGQL