A collapsible select list with checkboxes for children items

I am currently developing a website using Vue.js, HTML, and SCSS. I am looking to implement a drop-down functionality similar to the animated example provided in the gif below:

https://i.stack.imgur.com/Mia2D.gif

The gif demonstrates how the drop-down menu should behave; when a hotel is selected, the drop-down should display the available room types within that specific hotel.

I have managed to create a basic version of the drop-down using HTML and Vue's v-if directive. However, the code is complex and contains some bugs. Are there any existing packages or examples that offer a similar drop-down solution? Any suggestions would be greatly appreciated.

Thank you in advance...

Below is my current code:

(Code snippet here)
(More code snippet here)

Answer №1

Take a look at this helpful solution I've prepared for you. It includes a small component to assist you in making modifications to your code. Hopefully, this will be beneficial to you.

 <template>
  <div class="container">
    <form>
      <div class="row">
      <div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
        <div class="form-group">
          <select v-model="selectedValue">
          <option  v-for="(val,key) in formData" :key="key">{{key}}</option>
        </select>
        </div>
        <div class="form-group">
          <app-checkbox :childData="selectedChildData"></app-checkbox>
        </div>
      </div>
    </div>
    {{selectedChildData}}
    </form>

  </div>
</template>

<script>
import AppCheckbox from "./AppCheckbox"
export default {
  data(){
    return {
      formData:{
        test1:["single","double"],
        test2:["sample1","sample2"]
      },
      selectedValue:"",
      selectedChildData:[],
      formDataSelected:[]
    }
  },
  watch:{
    selectedValue(val){
      this.selectedChildData = this.formData[val]
    }
  },
  components:{
    "app-checkbox": AppCheckbox
  }

}
</script>

<style>
</style>

Below is the code snippet for the AppCheckbox Component:

<template>
    <div>
        <div class="form-group" v-if="customData.length != 0 || customData.length != null" v-for="(val,index) in customData" :key="index">
            <input type="checkbox" :value="val" v-model="childSelectedData">{{val}}
        </div>
    </div>
</template>
<script>
export default {
    props:{
        childData:Array
    },
    data(){
        return {
            childSelectedData:[]
        }
    },
    computed:{
        customData:{
            get(){
                return this.childData;
            }
        }
    }
}
</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

Unable to store loop information fetched from api into a JSON file

I'm currently facing an issue with my code where I am trying to save the results from looping through an API into a JSON file using writeFileSync. Here is the code snippet in question: function processRarity(limit) { var resultJson = []; for ( ...

Using Slick.JS to Sync Navigation with Main Slider, Automatically Resetting to First Slide

I have a question about the functionality of the Slick.JS plugin that I'm using. In my project, I have two carousels with five slides each. The top carousel displays one slide at a time, while the bottom carousel shows all five slides concurrently. My ...

Ways to alter the div post user authentication

I'm in the process of developing a website with a single-page application setup. I'm utilizing Node.js for the backend and Angular for the frontend. The challenge I'm facing is displaying a specific div when a user is not logged in, and swit ...

Incorporate SVG files into a TypeScript React application using Webpack

I am trying to incorporate an SVG image into a small React application built with TypeScript and bundled using Webpack. However, I am encountering an issue where the image is not displaying properly (only showing the browser's default image for when n ...

The variable (form.onsubmit) remains unset even after assigning a value

function setFormOnSubmit(formName){ if(!formName) return; var form = document[formName]; form.onsubmit = function(){ console.log('This is the onsubmit function'); }; console.log('onsubmit successfully set ...

Filtering data from Arduino using web serial communication

My setup consists of an Arduino kit connected to a webserial API that sends data to an HTML div identified by the id 'target'. Currently, all the data is being logged into one stream despite having multiple dials and switches on the Arduino. Th ...

When attempting to declare a functional component in React utilizing styled-components in TypeScript, an error is encountered stating "No overload matches this call."

Playground https://codesandbox.io/s/typescript-type-checking-question-0b42t Sample Code type BadgeTypes = { success: string; secondary: string; alert: string; text: string; }; type Theme = { fonts?: object; borderRadius: string; primary?: o ...

Tips for centrally zooming responsive images without altering their dimensions

I have created a custom jQuery and CSS function that allows an image to zoom in and out on mouseover while maintaining a constant box size. I modified an example code to suit my needs. Check out the demo here: https://jsfiddle.net/2fken8Lg/1/ Here is the ...

What is the best way to retrieve the value of a textbox in AngularJS?

Trying my hand at creating a basic web page using angular. I've got 2 textboxes and 2 buttons - one to set a predefined value in a textbox, and the other to add some text. Here's the code snippet: <!DOCTYPE html> <html lang="en" ng-app ...

Is there a way for me to use an ajax xmlhttprequest to submit all the selected values from my radio buttons?

Here's the situation: I have four input forms [A-D] and I have selected options A and B. I want to transfer this information to another page, but I'm not sure how to do it. I've tried searching for tutorials on AJAX, but most of them focus ...

The angular.copy() function cannot be used within angular brackets {{}}

Within my controller, I am utilizing the "as vm" syntax. To duplicate one data structure into a temporary one, I am employing angular.copy(). angular.copy(vm.data, vm.tempData = []) Yet, I have a desire to transfer this code to the template view so that ...

Developing a division with an image source based on the selection of a checkbox

My goal is to develop a "change function" that generates a new div for each checked checkbox selection and removes the div when the checkbox is unchecked. These new divs should also display the img src of the selected checkbox. Currently, my JavaScript c ...

Issue with content not wrapping inside the body tag (apart from using float or setting body and html to 100

Why on earth is the body/html or .main div not wrapping my .container div's when the browser width is between 767-960 px?! This is causing horizontal scrolling and I am completely baffled. This should definitely be working! The only code I have is: ...

Show the name of the current user in a WordPress form using a readonly input field

How can I display the logged-in WordPress username (display name) in a form input field that is set to readonly? I have already checked out the Function Reference/wp get current user, but haven't had any success with it. Take a look at the code snip ...

Is there a way to retrieve the left offset of a floating element even when it is positioned outside the viewport?

My current situation involves creating several panels that are stacked side by side within a main container. Each panel takes up 100% of the viewport width and height. I want to be able to horizontally scroll to each panel when clicking on their respective ...

Error: Module not found - Unable to locate 'dropzone'

Since migrating from Angular 4.4 to Angular 8.0, I encountered the following issue: ERROR in ./src/attributes/import/import.component.ts Module not found: Error: Can't resolve 'dropzone' in 'C:....\src\attributes\imp ...

It appears that the jQuery $.get and $.post methods are not functioning as expected

Hey everyone, I'm facing an issue with two PHP session variables that I need to clear on click. I've attempted using both $.get and $.post AJAX methods to trigger an external PHP script that should reset the values of these session variables. How ...

Converting jQuery into Methods within a VueJS function

How can I implement this function as a method in VueJS? $(document).ready(function(){ $(".slide").hover(function(){ $(this).find("div.snipit").slideDown("slow"); },function(){ $(this).find("div.snipit").slideUp("slow"); ...

What methods are available to adjust the header color on various pages?

I have a solution that works for one location, but I need to add red color to multiple locations. How can I achieve this? import { useRouter } from "next/router"; function Header() { const router = useRouter(); return ( <> & ...

"The FindByIdAndUpdate function is successfully updating the data, but it is unexpectedly

This is my first time seeking guidance here, as I've reached a dead end with my issue. I am currently working on a household collection that includes a member collection within it. Whenever new members join, I need to update the household collection ...