Modify the value within vc-date-picker > v-text-field by utilizing v-for

I need the value :value to automatically update from inputValue.start to inputValue.end. This means that when I click on the end date, it should be reflected in the second text field. Similarly, if I select a date range in the second text field, the first text field should also update accordingly. Below you can see the result of both scenarios.

P.S.: My implementation uses the V-Calendar plugin for Vue.js. The vc-date-picker element is part of this plugin.

  • HTML:

<v-col v-for="(dateF, date_id) in datesF" :key="date_id + 'A'" cols="6" sm="3">
  <vc-date-picker v-model="range" color="red" is-range :input-debounce="500" :min-date="new Date()">
    <template v-slot="{ inputValue, inputEvents }">
      <v-text-field 
        :value="inputValue.start" 
        v-on="inputEvents.start" 
        :label="dateF.label"
      />                          
    </template>
  </vc-date-picker>
</v-col>

  • Script:

<script>
  export default {
    name: "Home",
    data: () => ({
      datesF: [
        { label: "Start Date", val: "start" },
        { label: "End Date", val: "end" },
      ],
      range: {
        start: new Date(),
        end: new Date(),
      },
    }),
  }; 
</script>

View Result 1 View Result 2

  • What I have attempted:

    :value="inputValue + '.' + dateF.val"
    did not solve the issue.

  • EDIT: I have found that without using v-for and having two v-text-field, the solution works. However, I prefer to use v-for as it allows me to align the text fields in one line. Despite several attempts, I couldn't get it to work with v-for. It seems to only work with an individual v-text-field, but I am determined to find a solution with v-for.

Temporary Solution (with v-for)

Please refer to @Gurkan Ugurlu's answer below.

  • The limitation of this temporary fix: There is no live update. Refer to this GIF.

For Live Update based on my original code:

My initial code simply outputs the data for testing purposes, which has been successful so far. Each time a date range is selected, console.log displays the current dates.

watch: {
    range: {
      handler: function () {
        console.log(this.range.start.toLocaleDateString());
        console.log(this.range.end.toLocaleDateString());
      },
    },
},

Answer №1

Would you like to give this a shot? Hopefully, it will be beneficial for you :)

<v-col v-for="(dateF, date_id) in datesF" :key="date_id + 'B'" cols="6" sm="3">
  <vc-date-picker v-model="range" color="blue" is-range :input-debounce="200" :min-date="new Date()">
    <template v-slot="{ inputValue, inputEvents }">
      <v-text-field 
        :value="inputValue[dateF.val]" 
        v-on="inputEvents[dateF.val]" 
        :label="dateF.label"
      />                          
    </template>
  </vc-date-picker>
</v-col>

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

What are some effective strategies for avoiding the issue of a hook being invoked multiple times?

Having an issue with my vue3 project. Essentially, I need to handle different layouts for various scenarios such as authorization, user profiles, and group layouts. Here's my approach: Create a component AppLayout.vue to manage layouts <template& ...

Creating diverse content for various tabs using JavaScript

I have developed a code that uses a for loop to generate tabs based on user input. var tabs = ""; var y = 1; for (var x = 0; x < tabNum; x++) { tabs += "<li class = 'tabbers'>" + "<a href='#tab'>Tab</a>" + "& ...

Turn only one bracket on the accordion

When clicking on a specific header, I want only one chevron to rotate instead of all the chevrons rotating. I am currently unsure how to specify which chevron should rotate individually. My project is in ASP.NET MVC 5 and I am using razor view to loop th ...

Storing the .NET Framework viewmodel in its own individual Javascript file

I have a question about structuring my design for SoC (Separation of Concerns). I currently have the following files: testController.cs testViewModel.cs testView.cshtml testScript.js Currently, I generate data in the controller, populate the testViewMod ...

Header Stability TransitionAndView

I'm not very experienced with JavaScript, so please bear with me. I'm attempting to create a fixed header that transitions to 50% opacity when scrolled down and returns to full opacity (opacity: 1.0) when scrolled back to the top. Here is my cur ...

Utilizing the getJSON Method to Automatically Fill a Dropdown Selection Element

I am looking to populate a dropdown select menu with bank names and IIN numbers obtained from the following JSON: JSON Data : {"status":true,"message":"Request Completed","data":[{"id":1,"activeFlag":1,"bankName":"Union Bank of India","details":"Union Ba ...

Tips for passing the element ID as an argument in the jQuery upvote plugin function

var updateVote = function(data) { $.ajax({ url: '/vote/', type: 'post', data: { id: data.id, up: data.upvoted, down: data.downvoted, ...

Adding metadata fields to an existing Markdown file within TinaCMS

Is it feasible to enhance a Markdown file using TinaCMS by introducing new frontmatter fields? Instead of generating a brand new Markdown file, my goal is to modify the current one by appending new frontmatter fields. Currently, I am able to modify a sin ...

When I make a request to the API, I end up being redirected back to the Home page with a

I am currently working with the following controller: namespace App\Http\Controllers; use App\Models\Book; use Illuminate\Http\Request; class BookController extends Controller { public function index() { $user = ...

Run code from an inline script that is retrieved from an external origin

I am encountering an issue with my React app where I need to fetch index.html from one server location and run its scripts from another server location: const entries = await axios.get(`http://localhost:xxx`); let domParser = new DOMParser(); let tempDO ...

Utilizing a combination of MVC, jQuery, and Ajax to ensure that JavaScript is fully loaded before proceeding

Utilizing ASP.NET MVC and jQuery, I am loading a PartialView via Ajax which has its own accompanying JavaScript file. Upon successful retrieval of the html content, it is inserted into the DOM. However, there can be a delay between the insertion and the ex ...

Tips for importing several makeStyles in tss-react

When upgrading from MUI4 to MUI5 using tss-react, we encountered a problem with multiple styles imports in some files. const { classes } = GridStyles(); const { classes } = IntakeTableStyles(); const { classes } = CommonThemeStyles(); This resulted in ...

AngularJS encountered an unidentified provider: $routeProviderProvider

I've hit a roadblock with an unfamiliar provider error and can't seem to figure out what I'm missing. Here's the setup: in main.js 'use strict'; angular.module('myApp') .controller('MainCtrl', ['n ...

Attempting to open and display the contents of a text file (.txt) within a modal dialog box upon clicking a button

I am attempting to develop a modal that will appear when the user clicks on a specific button. The goal is for this modal to showcase text retrieved from a separate file stored on the server. My aim is to show this text within a dialog box modal. So far, ...

Utilizing a shared service for multiple JSON datasets in AngularJS: A beginner's guide

After successfully creating a service that retrieves data from a local JSON file and uses it in a controller to display it in the browser, everything seems to be working well. Here is the code snippet: JavaScript Code: var myApp = angular.module("myApp", ...

What is the reasoning behind an empty input value being considered as true?

I am facing an issue with the following code that is supposed to execute oninput if the input matches the answer. However, when dealing with a multiplication problem that equals 0, deleting the answer from the previous calculation (leaving the input empt ...

What is the method for rendering an ejs template from express using fetch without the need to submit a form?

login.js file: const form = document.getElementById('loginForm'); form.addEventListener('submit',async(e)=>{ e.preventDefault(); return await fetch(`localhost:8000/route`, { method: "get", heade ...

Trouble organizing a collection of destinations based on their geolocation and proximity

To address this issue, my approach has been to feed variables into the value attributes of an option list and then sort it based on these values. When manually assigning values, everything works smoothly, for example: <option id="link1" value="1">A& ...

The loading icon in JavaScript failed to function when JavaScript was disabled in the browser

On my blogger website, I tried using JavaScript to display a loading icon until the page completely loads. However, this method did not work when JavaScript was disabled on the browser. Only CSS seems to provide a solution. document.onreadystatechange = ...

How to display 3 items per row in a React table by utilizing a map function loop

Currently, my table using material UI generates one column on each row. However, I would like to display 3 columns as items on each row. Below is the mapping for my table: <TableBody> {this.props.data.slice(page * rowsPerPage, page * rowsPerPage ...