displaying date picker on button click with angular bootstrap ui

I am trying to display an AngularJS Bootstrap calendar only upon clicking a button, and I want to restrict it from appearing when clicking on the input field. Below is my code:

<input type="text"
                   onkeydown="return false;"
                   onkeyup="return false;"
                   id="dateFrom"
                   placeholder="{{datePlaceholder}}"
                   datepicker-popup="{{format}}"
                   ng-model="leadFormData.myDate"
                   is-open="field.opened"
                   close-text="Close"
                   name="Received On"
                   max="maxDate"
                   min="minDate"
                   data-ng-disabled="disableDate"
                   class="calendar-view" />

    <button style="height:34px;" class="btn btn-default" ng-click="open($event)">
      <i class="icon-calendar"></i>
    </button>

I have created an open function that should be triggered upon the button click, however, it is not working as expected. Can you please help me identify where the issue might be?

 $scope.open = function($event) {
                    $event.preventDefault();
                    $event.stopPropagation();
                    $scope.field.opened= true;
                    };

Answer №1

If you're experiencing issues with dates in your project, consider implementing the angular bootstrap ui date picker. Here's how you can do it:

In your HTML file:

<input type="date" 
    id="startDate"
    class="form-control" 
    onkeydown="return false;"
    onkeyup="return false;"
    datepicker-popup 
    data-ng-model="searchQuery.startDate" 
    is-open="startDateOpened" 
    datepicker-options="dateOptions" 
    show-button-bar="false" />
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="fa fa-calendar"></i></button>

And in your controller:

$scope.open = function($event) {
            $event.preventDefault();
            $event.stopPropagation();

            $scope.startDateOpened = true;
        };
$scope.dateOptions = {
            formatYear: 'yy',
            startingDay: 1
        };

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

The JavaScript alert message pops up two times consecutively

I encountered an issue while attempting to utilize a module named disclaimer in Drupal 7. The alert message "You must enter the year you were born in." appears twice and then redirects to a URL that should only be accessed after verifying that you are over ...

Generate a div dynamically and incorporate a function that triggers on click event dynamically

In my current project, I am faced with a challenge due to laziness. My goal is to automatically generate menu buttons that are linked to different sections of a page using raw JavaScript. The issue arises when the body content of my site is loaded from an ...

Stop angular schema form's destroyStrategy from deleting any data

After upgrading my Angular app from version 0.8.2 to 0.8.3 of Angular Schema Form (ASF), a significant bug emerged. The application features multi-page forms that utilize prev/next buttons for navigation. A condition is implemented to display only relevan ...

Is there a way to preserve all the downloaded node modules in the package.json file?

Is there a way to keep track of all the node modules installed in package.json without the need for reinstalling them? I've heard about running npm init --yes, but I'm not entirely convinced if that will do the trick. Any assistance on this mat ...

saving a JSON element in a JavaScript array

Currently, I am utilizing AJAX to fetch data from a database using PHP and then converting it into JSON format. <?php echo json_encode($data); ?> This is the AJAX function being used: ajaxCall("getdata.php", container, function (data) { var co ...

Improving the efficiency of my conditions in a function with Vue JS

Does anyone have any suggestions on how to optimize this function? I feel like it could be shortened to improve its efficiency. Any help or advice would be much appreciated. Function: onStudentActionSelect: function () { if (this.selectedRows.length ...

Simulating a PubSub publish functionality

I have been trying to follow the instructions provided in this guide on mocking new Function() with Jest to mock PubSub, but unfortunately I am facing some issues. jest.mock('@google-cloud/pubsub', () => jest.fn()) ... const topic = jest.fn( ...

When the "open" prop is set to "true", the DRAWER component from @material-ui/core fails to display

Help Needed: I'm struggling to make the drawer component open when the variant prop is set to "temporary". Material-UI Package Used: @material-ui/core I have integrated Material UI's drawer component into my custom Nav component. However, I am ...

Unlawful use of the return statement

Can you identify the issue with this code? The browser reports: "Uncaught SyntaxError: Illegal return statement" I'm looking for an explanation in this format: 1 2 3fool 4 5bar 6fool 7 8 9bar... let arr = []; for (i = 0; i <= 100; i++) { if ( ...

What are the distinctions between utilizing util.inherits() and prototypes for inheritance in node.js?

The method util.inherits() allows for the inheritance of methods from one function to another. Prototypes are also a way to achieve inheritance in JavaScript. I am wondering when it is best to use .inherits() versus changing the prototype chain. Any advi ...

Removing a session when the client has left

I wanted to simplify what I'm trying to achieve. Imagine two people have PHP sessions on a webpage. One person leaves the page while the other remains. After 60 seconds, the session of the person who left should be terminated automatically (like a ti ...

Identify all td inputs within a TR element using jQuery

Is there a way to retrieve all the input values within each table cell (td) of a table row (tr) using jQuery? Suppose I have a tr with multiple td elements, and some of these tds contain inputs or select elements. How can I extract the values from these in ...

Can anyone recommend an easy regular expression to validate date format patterns?

While searching for regex patterns to validate date values in a specific format, I came across numerous options. However, I prefer to allow users to input their own custom date patterns such as: d-mm-yyyy MM/dd/yy yyyy.mm.d I am looking for a ...

The ReactJS application is experiencing issues when run on an outdated version of Chrome, specifically version

I recently set up a new ReactJS project using create-react-app, with node Version 12.22.12. To ensure compatibility with older browsers, I incorporated the polyfill core-js. As a result, the project now functions smoothly on Chrome versions 31 and above; h ...

Positioning an element in the center of another using JQuery

Greetings! I am currently working with some elements that look like this: <div id="one">content</div> <div id="two">content</div> These elements are followed by another set of elements (without any parent, placed directly after th ...

Identify all elements that include the designated text within an SVG element

I want to target all elements that have a specific text within an SVG tag. For example, you can use the following code snippet: [...document.querySelectorAll("*")].filter(e => e.childNodes && [...e.childNodes].find(n => n.nodeValue ...

Creating a global variable in Angular that can be accessed by multiple components is a useful technique

Is there a way to create a global boolean variable that can be used across multiple components without using a service? I also need to ensure that any changes made to the variable in one component are reflected in all other components. How can this be ac ...

Tips for operating an Express application with React in production mode

My web application has a specific file structure as shown in the image below. https://i.stack.imgur.com/Etzdb.png I'm facing difficulties running my web app with the React Production Build. The following code snippet in my index.js doesn't seem ...

Techniques for transferring JavaScript variables within a URL using AJAX

Is there a correct way to pass the values of accesstoken and pageid inside the URL I am using? Any ideas on how to do it properly? <script type="text/javascript"> function makeUrl() { var accesstoken = "12345679|bababashahahhahauauuaua"; ...

The view in Ionic 2 does not update appropriately when using promises

There appears to be a delay in the application refreshing until after the next action is taken (such as clicking a button for the second time). Take, for instance: import {Component} from '@angular/core'; import {SqlStorage} from "ionic-angular ...