Is it possible to use conditional logic on child elements in formkit?

I am a bit confused about how this process functions.

Currently, I am utilizing schema to create an address auto complete configuration.

My goal is to have the option to display or hide the fields for manual input.

This is the current appearance of the form: https://i.sstatic.net/zvZg4.png

Initially, I want the blue section to remain hidden and only appear when Can't find your address? is selected

Here is my existing code:

{
    $formkit: InputType.GROUP,
    name: 'address',
    label: label,
    children: [
        // Code continues...
    ],
};

I am troubleshooting by attempting to change the text color from blue to red based on the status of the $manual option

attrs: {
   class: {
     if: '$manual',
     then: 'grid grid-cols-2 gap-4 ui-box py-5 px-4 mt-3 text-red-500',
     else: 'grid grid-cols-2 gap-4 ui-box py-5 px-4 mt-3 text-blue-500',
   },
},

However, despite my efforts, the color does not seem to change when selecting the manual option.
It appears as though the change is not being recognized.

I am referencing this example in playground which demonstrates what I am trying to achieve but it is not working properly for me.

What could be the issue?

Answer №1

Upon further investigation and experimentation, it has been discovered that the here it is necessary to include both the v-model and data attributes.

In order for functionality to be initiated, I had to make the following adjustments:

<template>
  <FormKit
    type="form"
    :actions="false"
    id="login"
    @submit="submit"
    v-model="data"
  >
    <FormKitSchema :schema="schema" :data="data" /> 
  </FormKit>
</template>

<script setup lang="ts">
import { Schema } from './schema.ts'

const data = ref({
  address: {
    manual: false,
  },
});
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Define a TypeScript function type that can return either an object or a string depending on whether it succeeds or fails

I encountered an issue with a function that either returns a Promise on success or a string on error. async create(createDebtorDto: CreateDebtorDto): Promise<Debtor> { console.log("createDebtorDto", createDebtorDto) try{ const createdD ...

Angular 4 HTTP Requests Failing to Retrieve JSON Data

I am currently working with the following method in my Typescript: allPowerPlants(onlyActive: boolean = false, page: number = 1): PowerPlant[] { const params: string = [ `onlyActive=${onlyActive}`, `page=${page}` ].join('&&apo ...

Vitest's behavior shows variance when compared to compiled JavaScript

Challenge Currently, I am developing a package that relies on decorators to initialize class object properties. The specific decorator is expected to set the name property of the class. // index.ts const Property = (_target: any, key: any) => { } cl ...

Retrieve information from a URL to transmit to a different page in NextJS using Typescript and AppRouter

I'm struggling with transitioning from the Home page to the Detail page. I've successfully passed data to the URL from the Home screen, but I'm having trouble accessing it in the Detail screen. I'm working with NextJS ver 13, using Type ...

"Implementing drag and drop functionality in Vue.js without the need for a

Exploring html 5 drag and drop functionality using vue js has been a challenging experience for me. After following the w3schools tutorial on drag and drop, I managed to get it working in a basic html file but faced difficulties when implementing it in my ...

Recursive array generation

Given an array 'featureList', the goal is to create a new array 'newArray' based on a specific ID. For example, for ID 5, the newArray would be ['MotherBoard','Antenna','Receiver'], where Receiver correspon ...

What is the best way to remove a selected item from an array in Vuejs when it has been clicked

I'm having trouble with my splice() method in this simple To-Do app. I want to delete a specific task by clicking a button, but the solutions I've tried from Stack Overflow aren't working for me. The items do get deleted, but only the last o ...

What steps should I follow to perform unit testing on a Quasar application with Jest?

I am currently working on a Quasar application that was created using the quasar-cli. I'm trying to figure out how to incorporate unit testing with a test runner like Jest for this type of application. In my Jest configuration, I included the follow ...

Encountering the error "When calling reset() in Vue JS, getting the error message 'Cannot read property 'map' of undefined' in the following file"

Encountering the following error when attempting to reset, as shown in the screenshot:- > vue.esm.js:1897 TypeError: Cannot read property 'map' of undefined > at c.setResults (store.js:61) > at vuex.esm.js:785 > ...

Exploring nested JSON data in Vue.js

In my attempt to access nested JSON within an array using Vue for a simple search functionality, I encountered a problem. Each school is encapsulated in a "hit" array, causing the system to perceive only one result of "hit" instead of returning data for ea ...

Define the data type for the toObject function's return value

Is it possible to define the return type of the toObject method in Mongoose? When working with generics, you can set properties of a Document object returned from a Mongoose query. However, accessing getters and setters on these objects triggers various v ...

The user authentication service indicates that no user is currently logged in

Currently, I am working on implementing a route guard to distinguish between authenticated users and guests. In order to achieve this, I have created an auth-guard service along with an auth service. Although the user data is successfully stored in the loc ...

JavaScript format nested data structure

For my latest project, I am working on a blog using Strapi combined with Nuxt. To fetch the categories and articles data for my blog, I send a JSON object from my front-end application using Axios. { "data": [ { "id": 1, ...

Firebase causing Nuxt async to fail on page reload

I'm encountering a problem with asyncData() when I refresh the page. On navigating from a list to a single item, it works fine. However, upon reloading the page, I see an empty object. In my page, I have the following code: <template> <di ...

What's the best way to add animation to the send icon while hovering over the button?

<div class="text-center"> <button [disabled]="btnStatus" class="btn btn-secondary buttonSend" type="submit"> <div [hidden]="btnStatus"> Send Message&nbsp;&nbs ...

Parameters in Typescript decorators

Can someone help me understand the various parameters of a Typescript decorator? function myDecorator(target) { // do something with 'target' ... } In the given example, I am aware that 'target' represents the function/class to wh ...

What is the best way to display the currently selected value in a Vue select drop down?

Is there a way to make the selected item in a custom component dropdown appear, similar to this Vue.js question? I have debug output within my single file component (SFC). <script> export default { props: ['modelValue', 'options&apos ...

The EChart chart in Vue is not updating properly due to a malfunctioning watch feature

I have created a simple EChart component using EChart and Vue 2. <template> <div :class="className" :style="{height:height,width:width}" /> </template> <script> import * as echarts from 'echarts'; re ...

Having trouble updating the vue bootstrap table after sending data from child to parent component

I have successfully implemented a slot for the header in vue-bootstrap, allowing me to add a show and hide button with a search box in each column header. The header is placed within a slot and the fields data includes a showFilter property that toggles be ...

I'm experiencing an issue where posts are duplicated based on the number of comments they have. Any suggestions on how to

Currently, I am working on a project involving lumen and Vuejs. In this project, I have performed a left join operation between my 'likes' and 'comments' tables with my posts table. While the likes data is being retrieved correctly with ...