"Customizing Bootstrap calendar by applying styles to the start and end dates with the dateClass()

I have been attempting to customize my bootstrap vue calendar in a way that allows me to color the start and end dates with specific classes when they are selected, while also adding another class called .inTrip to all the days in-between. It seems like I'm making progress, but I've run into an issue where adding one class inside my function removes the others. For instance, my start date can't seem to have both the start class and the intrip class applied simultaneously, even though it should.

If you'd like to see the calendar component, you can find it here.

I'm hoping there's a different way to write the ternary statement so that all classes can be included without canceling each other out.

Thank you for any advice. I'll also provide an example of how it currently looks – you can see that the lines for the .intrip class show up, but if I click again, my .start class shows and the intrip class does not :/

https://i.sstatic.net/WAXaa.png

<template>
 <b-row>
    <b-col md="auto">
      <b-calendar v-model="value" weekday-header-format="short" hide-header nav-prev-year="disable" :date-info-fn="dateClass" @context="onContext" locale="en-US"></b-calendar>
    </b-col>
    <b-col>
      <p>Value: <b>'{{ value }}'</b></p>
      <p class="mb-0">Context:</p>
      <pre class="small">{{ context }}</pre>
    </b-col>
  </b-row>
</template>

<script>

export default {
  name: 'calendar', 
   data() {
      return {
        value: '',
        values: [],
        
        context: null
      }
    },
    methods: {
      onContext(ctx) {
       this.context = ctx
       if(this.values.length < 2){
       this.values.push(this.context.selectedYMD.split('-')[2])
       }else{
         this.values=[]
         this.values[0] = this.context.selectedYMD.split('-')[2]
       }
       console.log(this.values)
       
        
      },
       dateClass(ymd, date) {
         
        const day = date.getDate()
        console.log('VALUES', this.values)    
        return day >= parseInt(this.values[0]) && day <= parseInt(this.values[1]) ? 'inTrip' : day == parseInt(this.values[0]) ? 'start' :day == parseInt(this.values[0]) ? 'end':''
      
       }
    }
}
</script>

<style>
.inTrip{
  border-top:1px solid black;
  border-bottom:1px solid black;
}
.start{
background-color: #2E9CFF;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
border:1px solid black
}
.end{
background-color: #2E9CFF;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border:1px solid black
}
</style>




Answer №1

After implementing conditional statements, I managed to successfully handle the issue by dynamically adding values to the string.

Here is an example:

dateClass(ymd, date) {
         console.log('date',date)
         let classText = ''
         const day = date.getDate()
         if(day >= parseInt(this.values[0]) && day <= parseInt(this.values[1]) && day!==parseInt(this.values[0]) && day !== parseInt(this.values[1])){
           classText = 'inTrip'
         }
         if(day == parseInt(this.values[0])){
           classText = 'start'
         }
         if(day == parseInt(this.values[1])){
           classText = 'end'
         }

        
        return classText;  
        
      
       }

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

Upon launching my static page, the images mysteriously vanish or show up in a substandard resolution

My latest project involves creating a wedding website from scratch. The site features a simple parallax design with an abundance of images. I used only Html, CSS, and a touch of JavaScript to bring it to life. While testing the site on my local server, ev ...

Obtaining an identification number upon clicking within a Vue table and storing it in a Laravel controller

One of the challenges I'm facing is related to an action button that triggers a modal to open. Within this modal, there's a component where users can upload an image. However, I'm currently struggling with retrieving the ID of the item that ...

Is it possible to customize the appearance of the Facebook and Twitter sharing buttons?

Whenever I try to use the Twitter and Facebook share functionality, I am presented with the standard default share buttons that resemble: https://i.sstatic.net/W5ZN8.png https://i.sstatic.net/0MW3U.png I have reviewed the policies, which indicate: Do not ...

I am struggling to grasp the concept of ref unwrapping within a TypeScript template

I'm currently in the process of converting some Vue3 code from javascript to typescript, and I am struggling to comprehend the unwrapping of a ref/computed value in the template. I used to believe that the template would automatically unwrap reactiv ...

Empty query object in Vue 3 route

Issue with passing route query to axios request - it's coming back empty. route.query is returning empty when mounted, but returns {"filter[city]": "Vilnius" } in axios then. Tried using nextTick but still facing the same problem. ...

Is the Vue.js 2.x composition API completely compatible with TypeScript?

After migrating our vue.js 2.x project to typescript, I came across Evan You's comment in this issue: https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121 The Class API proposal has been dropped, so I switched to the regular option-based ver ...

SCSS: When hovering over one div, display a different div

My goal is to display the elements in another div when hovering over a specific div. However, my current code does not seem to be working as expected. At the moment, there is no response upon hover and it remains non-responsive. I would greatly appreciate ...

Customizing v-model in a Vue component

In an effort to simplify certain sections of my HTML code, I have created a small component: <template> <div class="form-group"> <label for="desc">{{label}}</label> <input id="desc" readonly type="text" class="form-con ...

In order to showcase an image ahead of another (stay tuned),

Help! I'm facing a dilemma here. I have an abundance of adorable animal images with unique facial expressions, but there's one problem - the eyes are hidden! I desperately want to showcase those captivating eyes. This is what my code looks like. ...

Using JavaScript to trigger an open dropdown menu in Bootstrap 4

I have a dropdown menu that is designed like this: <div id="actions" class="dropdown btn-group btn btn-outline-secondary" role="group"> <div id="actionToggle" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="fa ...

Unusual marker appearing on every page utilizing ionic v1 and angularjs

For some unknown reason, a dot appears at the upper left side of each page in my webapp: https://i.stack.imgur.com/nN61t.png It seems to be an issue with the HTML code. When I run the snippet below, the dot is visible: <ion-view view-title="Send fe ...

Using SVG background images in Internet Explorer versions 7 and 8: a guide to HTML, CSS,

I have created a unique SVG image to use as a background, but it's not displaying in Internet Explorer 8 and earlier versions. I tried using tools like or http://code.google.com/p/svgweb/, but they only support SVG for IMG and Object elements, not ba ...

A guide to resolving a minor issue when transitioning ".slice()" to setup() as a computed function

Currently, I am utilizing Vuejs3 and attempting to transition .slice(0,3) (which limits v-for to 3) into a computed function within the setup(). This adjustment is aimed at restricting the number of elements in a v-for loop, particularly one that is nested ...

Creating fluid designs for my boxes with CSS to enhance responsiveness

I have designed my HTML file with 8 boxes that appear correctly on desktop, but when viewed on mobile devices, the columns are misaligned and shifted to the right side instead of being centered. How can I make it more responsive? See Preview Here is the ...

Utilizing CSS and Tailwind with either flexbox or grid to showcase repeated information in a layout of three rows

For a school project, I am exploring the use of CSS and Tailwind to enhance my learning. My task involves displaying data using a loop in Vue. The challenge is that this data needs to be presented in rows of 3, 2, and 3 in desktop view, while appearing sta ...

Ways to showcase flair in PHP code such as this

I currently have this code snippet: <h2 class="index-single">Tech Categories</h2><?php $args2 = array( 'cat' => 11 , 'posts_per_page' => 9 , 'paged' => $paged ); $the_query2 = new WP_Query( $args2 ); ...

Enhancing webpage performance by updating CSS properties dynamically based on mouse movement using JavaScript

My jQuery function is changing the background-position property of three elements when the user moves their mouse, but it's causing some performance problems. It's worth mentioning that the background images of these elements are SVGs. Here&apo ...

How to convert columns into rows using CSS grid

Is it possible to change the layout of a CSS grid from 3 columns to 1 row using media queries? Specifically, I want the first column to become the first row and take up the full width, while the second and third columns should combine to form one row with ...

Vue 3 Option api: Issue with v-model input not propagating from child component to parent element

I am currently working on a new project using Nuxt 3, and I have encountered an issue with a contact form where the input values from a child component are not being received by the parent element. Let's dive into the code breakdown: Parent Component ...

"Encountering Server Unavailability Issue while Deploying Vue App to Azure App Service on Linux

Working on developing a web app with Vue and Azure App Service on Linux has been successful locally. However, encountering a "Service Unavailable" error when attempting to build it on the server. The project is utilizing NUXT, with the port currently set ...