What is the method for assigning an initial or default value to a date field?

Having trouble implementing a date picker in angularjs and bootstrap due to the following issues:

  • The initial date is not set
  • When trying to open one date picker, all date pickers open

Below is my code snippet: http://plnkr.co/edit/elrOTfEOMmUkPYGmKTdW?p=preview

$scope.dateOptions = {
  maxDate: new Date(2020, 5, 22),
  minDate: new Date(1970,1,1),
  startingDay: 1
};
function disabled(data) {
 return true
}

$scope.open1 = function() {
  $scope.popup1.opened = true;
};

$scope.formats = ['dd-MMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
$scope.popup1 = {
  opened: false
};

Why do all date pickers open when only one is clicked? Image for reference below.

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

Answer №1

The initial date has not been set yet.

This issue arises because the model is being set to a string instead of an actual date object. To resolve this, make sure to do the following:

date: {
  date: 'date',
  name: d // avoid using moment(d).format('DD-MMM-YYYY')
}

Why does opening one date picker trigger all the date pickers to open?

When utilizing ng-repeat to generate multiple inputs, you must have separate properties for the is-open attribute on each input. It is recommended to include an opened property in the repeated items like so:

date: {
  date: 'date',
  name: d,
  opened: false
}

Then, on the button click event, pass in the corresponding item:

ng-click="open1(x)"

Ensure to set the is-open attribute correctly:

is-open="x.opened"

Lastly, update the opened property as follows:

$scope.open1 = function(x) {
  x.opened = true;
};

You can find the plnkr demo here.

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

Transfer PHP variables into a JavaScript array for dynamic data population

Similar Question: Dynamic Pie Chart Data in Javascript and PHP This snippet of code is utilized for populating a pie chart using javascript: <script type="text/javascript"> var agg = { label: 'Aggressive', pct: [60, 10, 6, 30, 14 ...

How to hand off control to a different controller within an AngularJS application

Just starting out with angularjs and still wrapping my head around the concepts. Here's the scenario I'm facing - I have 2 peer controllers (no parent-child relationship), where controller1 executes steps 1 to 10, and controller2 does something ...

Tips on concealing confidential keys within a React.js application on the frontend aspect

Desperate times call for desperate measures - I am attempting to conceal a secret key within my React frontend application. While I understand the risks involved, I feel compelled to do so without any other viable options. The reason behind my actions is ...

modifying prop values with Vue.js method

I'm currently diving into Vue and tackling a project that heavily relies on vue.js. My goal is to display data in a component using a prop, and now I'm looking to implement a method to increment the quantity of a product. Below is my code snippe ...

Is there a way to invoke a function once grecaptcha.execute() has completed running, but in response to a particular event?

Presently, the JavaScript function grecaptcha.execute is triggered on page load, as shown in the first example below. This means that the reCAPTCHA challenge occurs as soon as the page loads. A more ideal scenario would be to trigger it when the form submi ...

Utilizing Thymeleaf With JavaScript in Spring Boot: A Comprehensive Guide

Within my Spring Boot project, I am attempting to utilize Thymeleaf for injecting data into a JavaScript file that undergoes preprocessing with babel via WebPack. The Thymeleaf setup is outlined as follows: @Bean public SpringTemplateEngine templateEngine ...

Is it possible to assign variables inside an http call from a function in AngularJS?

Seeking urgent assistance. I need help with a function that resembles the following: $scope.getData = function(id) { $http.get('/url' + id).success(function (data) { return data.a.b.c; }); }; In another function, I have the fol ...

Error encountered: "Jest error - TypeError: Unable to access property 'preventDefault' because it is undefined."

I encountered an issue while testing the function below, resulting in the error mentioned above. function toggleRecovery = e => { e.preventDefault() this.setState( { recovery: !this.state.recovery }, () => { ...

Next.js is perplexing me by throwing an error about Event handlers not being able to be passed to Client Component props, even though the component clearly has "use client" at

My bundler generates a basic React component like this "use client"; "use strict";var a=Object.create;var r=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,s=Objec ...

What is the method to designate the initial value of a <select> tag within a React component?

I am working with a basic <select> element that is looping through a set of options: <select onChange={(event) => this.setState({selectedOption: event.target.value }) }> { this.state.options.map(option => <option key={option.label} ...

Angular and Firefox are flagging the response from my OAuth call as incorrect, however, Fiddler is showing a different result

Currently, I am in the process of developing a Cordova application and require OAuth authentication with my Drupal backend. My main issue lies in obtaining a request token for this purpose. Despite receiving a 200 response indicating success, when inspecti ...

At what point does angular2 @output get resolved?

Click on this link Here is the HTML code snippet: <chart [options]="options" (load)="saveGraphInstance($event.context)"></chart> <div (click)="switchGraph()">switch</div> <div (click)="showLoadingForce()">show loadin ...

Alexa Account Linking - Error: Account linking credentials are not valid

I've been working on setting up an Alexa skill with account linking. After obtaining the Linking Authorization Code and exchanging it for an Access Token, I attempted to input all the necessary parameters: code, access token, and skill ID into the Ale ...

Beginner: Interested in creating a web application with HTML, CSS, AngularJS, NodeJS, and MySQL?

After extensive searching on the internet, I have yet to come across a definitive answer. I am in the early stages of developing a web application and want to ensure that I am using the correct languages before diving too deep into it. Currently, my plan ...

Ways to specify the styles for tr, td, and label elements within a material table

Hey there! Currently, I'm working with material table in react. I came across this page: https://material-table.com/#/docs/features/styling, where it mentions that we can use cellStyle, headerStyle. But what if I want to add more detailed styles to e ...

What is the best way to adjust the CSS of an element within the #shadow-root (open) in web development?

When dealing with a "#shadow-root (open)" element, it appears that manipulating the style using only CSS is not feasible. The shadow-root was generated by a third-party JavaScript script and displays an element as an overlay on the page that I am trying to ...

Data cannot be transferred to a child element unless it has been initialized during the definition phase

Passing an array data from parent to child component has brought up some interesting scenarios: parent.component.html: <child-component ... [options]="students" > </child-component> Status I: Setting the array on definition ...

ajax requests getting blocked after doPostBack

When a user clicks on an anchor tag, I am prompting them to download a file. In the onclick event, I am using __doPostBack to perform a partial page postback and return the downloadable file to the user. The issue I am encountering is that if the file is ...

The POST response I received was garbled and corrupted

Operating under the name DownloadZipFile, my service compiles data and constructs a Zip file for easy downloading. This particular service provides a response that contains the stream leading to the file. A Glimpse of the Service: [HttpPost] public Actio ...

Updating an iframe's content URL

I am currently working on building a website using Google Web Design and everything is going well so far. I have added an iFrame to the site and now I am trying to figure out how to change its source when a button is pressed. Most of the information I fo ...