Configuring date and time picker options on the fly

I am attempting to dynamically set the options for this datetimepicker plugin.

This is what I have in my controller

  $(document).ready(function () {

    var today = moment(new Date()).format("YYYY-MM-DD");
    var tomorrow = moment().add(1, 'days');

    $scope.datetimepickerOptions = {
      format: "YYYY-MM-DD",
      defaultDate: today // need to set today or tomorrow here
    };

 });

and this is my HTML

// Today's date option should be placed here
<input datetimepicker
       datetimepicker-options="{{datetimepickerOptions}}"/>

// Tomorrow's date option should be situated here
<input datetimepicker
       datetimepicker-options="{{datetimepickerOptions}}"/>

These options are used to set the initial values of the inputs/fields. In the first input, I want to display today's date for the user, and in the second input, it should show tomorrow's date.

What would you suggest?

EDIT

I tried doing it like this

    $scope.datetimepickerOptions = {
      todayOptions: {
        format: "YYYY-MM-DD",
        defaultDate: today
      },
      tomorrowOptions: {
        format: "YYYY-MM-DD",
        defaultDate: tomorrow
      }
    };

However, I encountered the following error

TypeError: option todayOptions is not recognized!

Answer №1

How about dividing your choices into two groups?

$scope.datepickerOptionsSet1 = {
      format: "YYYY-MM-DD",
      defaultDate: today
    };

$scope.datepickerOptionsSet2 = {
      format: "YYYY-MM-DD",
      defaultDate: tomorrow 
    };

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

Issue with Generating divs dynamically in Ionic Framework

I'm currently working on dynamically generating a board game using divs in AngularJS, like so: HTML: <div class="boardgame" ng-repeat="square in board"> <div class="square"></div> </div> JS: $scope.board = [ {value: ...

What is the best way to refresh a navigation bar after making an API request, such as when using Google Sign-In?

Struggling to grasp the hook concept in this particular scenario: The flow goes like this - the user logs in with Google, which updates the session state. Consequently, the visitorType state transitions from 'viewer' to 'buyside'... A ...

Exploring the integration of Stripe Checkout with React and Express.js

Seeking assistance with integrating Stripe Checkout into my React application. I need to create a route in my nodejs/express server that will provide the session id required for setting up Stripe Checkout on the front end. The aim is to redirect users to s ...

Can a direct link to a Redis server be established through a web browser?

Can a connection be established with a redis server directly from the browser? In node, you can create a TCP connection using var client = net.connect(port, host);. I'm curious if it's possible to achieve the same in the browser either through Br ...

I'm curious if there is a method to determine the status of a .net required field validator using JavaScript

I am attempting to determine the status of the "required field validators" within an .aspx file. By state, I am referring to whether they are enabled or disabled rather than if their contents are valid or invalid. I am aware that the enabled/disabled sta ...

Javascript code for toggling the visibility of a div element not functioning as expected

This problem is becoming quite frustrating as it appears to be straightforward but still doesn't work. Inside my document, I have <div id ="splashscreen" style="display:block"> <h3>title</h3> <p>text</p> &l ...

Parsing JSON data using PHP and AJAX decoding

I have been searching for a way to pass parameters between the server and client, but I am struggling to find a solution that works. Despite reading extensively online, I have not been able to come up with a functioning solution. Client Side function sen ...

Tips for creating a flexible Cell component in react-big-calendar:

Is there a way to make the cell of react-big-calendar flexible depending on the number of events, and enable scrolling? Here is a screenshot showcasing my issue: https://i.stack.imgur.com/K2h69.jpg ...

Why is the ui-icons.png file in the /assets/images directory not being served by Rails 5?

Utilizing Rails 5 alongside AngularJS and Bootstrap. I have created a directive that is responsible for generating a form which includes an icon sourced from ui-icons_444444_25x240.png. However, despite the fact that this file is stored in app/assets/imag ...

The appearance of the check box remains stagnant visually

Having trouble with dynamically changing the state of a checkbox based on a database value. Even though the value changes after a button click, the visual state of the checkbox remains the same. Here is the link to the JSFiddle for testing: http://jsfiddle ...

The functionality of $(selector).css() seems to be malfunctioning

I currently have an html div element stored in a variable var rows = ""; rows += "<div>1111 : Hi there</div>"; Despite multiple attempts, I have failed to add a background color to this div using the following methods: 1. $(rows).css({&apos ...

What is the best way to exit a for loop in jQuery?

let intervalTime = 800; for(let index = 1; index < 20; index++) { $("#slide"+index).delay(intervalTime).fadeIn(); intervalTime = intervalTime + 800; } Every time I click on a button, the value of "i" should reset to "0". I h ...

Retrieve the selected status and value of the option that initiates a multiple selection change event

Is there a way to track only the value that has been added or removed from a selection, rather than getting an array of all selected values? How can I monitor each individual option within a selector to identify which one has changed, instead of looking a ...

Utilizing jQuery AJAX to Send an HTML Array to PHP

In my current HTML forms and jQuery AJAX workflow within the Codeigniter Framework, I've encountered a common issue that has yet to be resolved to suit my specific requirements. Here's the situation: HTML - The form includes an array named addre ...

What is the best way to send the link's ID to an AngularJS controller?

I have a scenario similar to the following: <a href="#" title="Post 1" id="car1"> Audi car </a> <a href="#" title="Post 1" id="car2"> BMW car </a> How can I pass the ID to the controller? I attempted the following: <a href= ...

JavaScript Global Variables Keep Getting Reset

Here's the concept behind my project: I've created a simple game that utilizes a do/while function and a switch statement to determine the player's current room. When the player is in room 1, the switch selects room1 and executes the room1() ...

The system is facing difficulty in accessing the property 'user_first_name' as it is currently undefined

I'm having trouble registering a user with expressjs/mongoose as I keep receiving the error: TypeError: Cannot read property 'user_first_name' of undefined at C:\Quiz webPolitica\server.js:20:24 at Layer.handle [as handle_request] ...

Encountered a Server Error: Invalid hook call. Hooks are restricted to being called within the body of a function component specifically in _app.js

As someone new to React and Next JS, I am facing an issue with setting initial auth user data on the initial load from the __app.js file. Whenever I try to use dispatch, it throws an error saying "Invalid hook call". I understand that calling hooks in the ...

Is there a way to determine if jQuery Mobile has already been loaded?

I am dynamically loading jqm and I'm trying to determine if it has been previously loaded in certain scenarios. Is there a method to check for the presence of jqm? ...

Issue with Angular ng-src not able to load picture when using --livereload (REVISITED)

My Goal: My objective is to enable users to download images from the server to their device when they click on an image placeholder. The downloaded image path will then be stored in the $scope and shown to the user. Below is my controller: .controller(&a ...