Establish the predefined date for the air-datepicker

I am currently utilizing the air-datepicker inline feature.

My objective is to establish the starting date for it.

Below is the script detailing my attempt:

export function load_datepickers_inline():void {
const search_legs_0_datepicker = $("#search_legs_0_datepicker");
const leg_0_datepicker = $("#search_legs_0_datepicker").datepicker({
  language: gon.locale,
  classes: 'inline-picker',
  selectOtherMonths: true,
  showOtherMonths: true,
  changeMonth: true,
  changeYear:true,
  altField: '#search_legs_0_date',
  selectDate: new Date(search_legs_0_datepicker.attr("data-defaultDate")),
  minDate: new Date(search_legs_0_datepicker.attr('data-mindate')),
  maxDate: new Date(search_legs_0_datepicker.attr('data-maxdate')),
  altFormat: 'yy-mm-dd',
  onSelect: (dateText, inst) => {
    const date = new Date(dateText);
    if (!leg_0_datepicker) { return false; }
    leg_1_datepicker.datepicker("option", "minDate", date);
    if ($("#search_legs_0_hotel_date").length > 0) {
      $('#search_legs_0_hotel_date').datepicker().data('datepicker').update('minDate', date);
      $('#search_legs_0_hotel_date').datepicker().data('datepicker').datepicker("setDate", date);
      $('#search_legs_1_hotel_date').datepicker().data('datepicker').update('minDate', date);
    }
  }
})

const search_legs_1_datepicker = $("#search_legs_1_datepicker");
var leg_1_datepicker = $("#search_legs_1_datepicker").datepicker({
  selectOtherMonths: true,
  showOtherMonths: true,
  language: gon.locale,
  changeMonth: true,
  changeYear:true,
  classes: 'inline-picker',
  altField: '#search_legs_1_date',
  selectDate: new Date(search_legs_1_datepicker.attr("data-defaultDate")),
  minDate: new Date(search_legs_1_datepicker.attr('data-mindate')),
  maxDate: new Date(search_legs_1_datepicker.attr('data-maxdate')),
  altFormat: 'yy-mm-dd',
  onSelect: (formattedDate, date, inst) => {
    if ($("#search_legs_1_hotel_date").length > 0) {
      $('#search_legs_0_hotel_date').datepicker().data('datepicker').update('maxDate', date);
      $('#search_legs_1_hotel_date').datepicker().data('datepicker').update('maxDate', date);
      $('#search_legs_1_hotel_date').datepicker().data('datepicker').datepicker("setDate", date);
    }
  }
})

Everything seems to be in order, but the default date is not highlighted. Is there a specific setting required for this?

Thank you for your assistance.

Answer №1

According to the provided documentation, selectDate is a function that needs to be used in the following manner:

leg_1_datepicker.selectDate(new Date(2018, 3, 11));

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

Manipulate elements by adding and removing classes sequentially based on an array

Previously, some had difficulty understanding my question. I have an array of variables representing the ids of 5 divs. My goal is to change the color of each div sequentially for a brief moment before reverting back, mimicking the behavior of traffic ligh ...

What is the best way to replicate an Ajax call similar to the way Postman does it?

After successfully retrieving JSON data from a URL using Postman, I received an array as a JSON string. Below are screenshots of the process: https://i.stack.imgur.com/6uLSS.png https://i.stack.imgur.com/vDF0L.png I now want to achieve the same result u ...

When utilizing RxJS, the process of filtering Observable data may not function as expected if the filtering is carried out within a separate function rather than directly within the subscribe

While attempting to filter data from an external source using the RxJS filter on Observables, I encountered an issue where all records were returned instead of just the ones meeting the filtering criteria. This problem occurred when the code was within a l ...

Embarking on the GSAP journey

I'm attempting my first animation using GSAP, but no matter what I try, nothing seems to be working. I've even tried using example code without success. Within my PHP file, I have the following code snippet: <head> <script src="https:/ ...

Troubleshooting Node.js TypeScript breakpoints in Visual Studio Code

I've attempted multiple solutions, but none seem to be working for me. Although the code is running, I'm having trouble setting breakpoints and debugging it. Can you offer any assistance? Below is the configuration script I've tried in VSCo ...

javascript dynamic content remains unaffected by ajax call

I'm a beginner with javascript and I am using a PHP variable to create links dynamically. Here is an example of how the variable is set: $addlink = '<button class="blueBtn btnSmall" id="current'.$product_id.'" onClick=addcart(' ...

What is the reason for the lack of compatibility between the TypeScript compilerOptions settings 'noEmitOnError: true' and 'isolatedModules: false'?

Whenever I try to execute TypeScript with isolatedModules set as true and then false, I keep encountering this error message: tsconfig.json(5,9): error TS5053: Option 'noEmitOnError' cannot be specified with option 'isolatedModules'. ...

Issue with login form in IONIC: Form only functions after page is refreshed

Encountering an issue with my Ionic login form where the submit button gets disabled due to invalid form even when it's not, or sometimes displays a console error stating form is invalid along with null inputs. This problem seems to have surfaced afte ...

The object must contain a property 'children', which is required in the type '{ children: any; }' but missing in the type '{}'

While learning React from a variety of sources, I've encountered an issue with one of the examples. Error message: Property 'children' is missing in type '{}' but required in type '{ children: any; }' export default fu ...

What is the best way to make a select tag read-only before the Ajax request is successful

Is there a way to make a select tag read-only before an Ajax success? I tried using this code, but it didn't work: $("#tower").prop('readonly', true); Then I tried this alternative, but I couldn't get the value from the select tag: ...

What is the best method for rounding a decimal number to two decimal places?

Here is the JavaScript code I am using: $("input[name='AuthorizedAmount'], input[name='LessLaborToDate']").change(function () { var sum = parseFloat($("input[name='AuthorizedAmount']").val()).toFixed( ...

The load function is able to successfully load the page, however, it is unable to perform any actions with

When I use the following code: $('#categories').load("/Category/GetCats"); it calls the GetCats() method in this controller: public ActionResult GetCats() { var model = db.Cats .Where(c => c.user_id == 5); ...

What is the best way to manage the browser tab close event specifically in Angular, without it affecting a refresh?

I am trying to delete user cookies when the browser tab is closed. Is this achievable? Can I capture the browser tab close event without affecting refreshing? If I attempt to use beforeunload or unload events, the function gets triggered when the user ref ...

Uh oh! You haven't set a QueryClient yet. Make sure to use QueryClientProvider to set

My first experience with React Query didn't go as planned when I encountered this error at the beginning of my React app: Even though I added QueryClientProvider to the top of my component tree, I kept getting: Error: No QueryClient set, use QueryCli ...

The issue of dynamic select not sending the POST data

Having an issue with a form where the selected country and city are not being posted correctly. Despite different names in the form and php mailer script, both selections are coming through as the country. Here's the form: <select style="width: 6 ...

How to surround values and keys with double quotes using regular expressions in JavaScript

I am in need of a valid JSON format to request ES. I currently have a string that looks like this: { time: { from:now-60d, mode:quick, to:now } } However, when I attempt to use JSON.parse, I encounter an error because my ...

Using a function as an argument within an Angular directive

Looking for a solution to pass a promise-returning function into a directive? Here's what I'm currently doing: In the parent controller, I've created a callback: $scope.myCb = function(data) { console.log(data); } Directive Scope: sco ...

What is the best way to customize the link style for individual data links within a Highcharts network graph?

I am currently working on creating a Network Graph that visualizes relationships between devices and individuals in an Internet of Things environment. The data for the graph is extracted from a database, including information about the sender and receiver ...

Using Jasmine to Jest: Mocking Nested function calls

I am currently working on testing my TypeScript functions with Jasmine: //AB.ts export async function A() { } export async function B() { A(); } My goal is to unit test function B by mocking out function A to see if it is called. Here is the code I h ...

Facing an infinite loop issue with my ng-view and the index.html page in AngularJS

Hello everyone, I have a question regarding AngularJS ngview. I just started learning about Angular a week ago. In my code, the webpage is showing an infinite loop of the index itself instead of displaying the correct page. I've searched on Stack Ove ...