Utilizing ng-model-options updateOn:blur in conjunction with the uib-datepicker popup

There is an input field where a user can either enter a date manually or choose one from the uib-datepicker calendar (https://angular-ui.github.io/bootstrap/). When the user clicks on the input, the calendar pops up for date selection. Here is the input code:

<input
     datepicker-append-to-body="calendarCtrl.appendToBody"
     uib-datepicker-popup="calendarCtrl.dateFormat"
     ng-model="calendarCtrl.ngModel"
     ng-click="calendarCtrl.open"/>

I want to give users the option to update the ng-model only after they have finished typing and blurred out of the input field. To achieve this, I am trying to utilize ng-model-options.

 ng-model-options={updateOn: 'blur'}

This method works well when a user manually types in a date - the ngModel is not updated until the input is blurred, and any validation is deferred until then. However, there seems to be an issue with the calendar popup functionality. When a user tries to select a date from the calendar, nothing happens. It appears that clicking on the calendar triggers a blur event on the input field.

Has anyone encountered this issue before? Is there a setting within ng-model-options or the datepicker itself that would allow users to make a selection from the calendar without immediately updating the ng-model?

Thank you!

Answer №1

It seems like implementing a temporary property

ng-model="calendarCtrl.tempSelectedDate"
for the ngModel in the Date Picker could be helpful.

You can then utilize the ngBlur event (https://docs.angularjs.org/api/ng/directive/ngBlur) to update the actual property by setting

calendarCtrl.ngModel = calendarCtrl.tempSelectedDate
.

Furthermore, it is recommended to use more descriptive names like

ng-model="calendarCtrl.dateSelected"
instead of simply referring to the scope property as calendarCtrl.ngModel, as this will improve code readability.

For a demonstration, check out this functioning demo http://plnkr.co/edit/90mDPqzadjPt09Tp4SlI?p=preview.

I have enhanced an existing datepicker plnkr by adding ng-blur="blurDate = startDate" to the <input> and displaying the value with Blur Date: {{ blurDate }}.

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

Minimizing the size of a production application's bundle

In a production application I am working on, the bundle size is currently 8.06MB. # Output from npm build File sizes after gzip: 1.67 MB build/static/js/3.73cf59a2.chunk.js 794.29 KB build/typescript.worker.js 131.13 KB build/css.worker.js 1 ...

What causes z-index to be ineffective with sticky elements?

In my website, I've implemented rollover effects in a sticky footer and a responsive menu that stays at the top. However, when the menu is opened and extends over the footer, it covers everything except the rollovers. Closed navigation http://www.mus ...

Display the HTML content retrieved from the SailsJS Controller

Exploring the world of SailsJS, I am on a mission to save HTML content in a database, retrieve it, and display it as rendered HTML. To achieve this goal, I have set up a sails model and a controller. This is what my model looks like: attributes: { ht ...

Encountering a "Vue is not defined" error in Laravel 5.8 while constructing a comment system using Vue.js

I'm struggling to implement a comment system using Vue.js in my Laravel project. Despite my efforts, I keep encountering a "Vue not defined" error in the console. Can anyone shed some light on why this might be happening? Below is the code snippet I&a ...

Failure to return an error in the mongoose find function

While attempting to create some statics with Mongoose, I am facing an issue where I cannot access the error argument when using find() or findOne(). Below is my static method: User.statics.authenticate = function(login, password, cb){ return this.mode ...

What sets apart `npm install --save-dev gulp-uglify` from `npm install gulp-uglify`?

I'm feeling perplexed regarding the npm installation process. Based on what I've gathered, there are several options available to me when installing modules: The -g option which saves modules globally --save-dev No arguments. Could someone cl ...

Frontend and backend collaboration: encountering a 404 error with the Koa proxy

I have a backend Node application that I would like to connect with a frontend AngularJs app. Both the backend and frontend are part of the same repository but sit in different folders. The Node app is functioning properly, and I can successfully interact ...

Using Array.push within a promise chain can produce unexpected results

I have developed a method that is supposed to retrieve a list of devices connected to the network that the client has access to. export const connectedDevicesCore = (vpnId: string, vpnAuthToken: string) => Service.listVPNConnectionsCore ...

Trouble with Leafletjs Routing Machine collapse button loading issue

In my project, I am using django 1.10.5, booststrap 4.0, and LeafletJs 1.0.3 along with the routing machine plugin and geocoder. However, I have encountered an issue where the collapse button of the control panel for the routing machine does not appear (it ...

Having trouble with React's conditional rendering not working as expected?

I am currently working on updating the contents of my Navbar and Router by using useContext and conditional rendering techniques. Here is a snippet from my App.js: import "./App.css"; import axios from "axios"; import { AuthContextProv ...

When modifying v-model directly in a Vue instance, the Vuetify component on the screen may not update its displayed value

Within my Vue component example (utilizing Vue 2 and Vuetify 1), I have implemented an input field for user data entry. However, I am looking to programmatically alter the input field's data to a specific value. For instance, in this scenario, I aim ...

What steps are involved in enabling Server Side Rendering with Next.js?

For my exploration of Next.js, I started by setting up a new Next.js project and incorporating code to retrieve weather data: export default function Home() { const [data, setData] = useState(null); useEffect(() => { fetch("https://api.we ...

How can jQuery help me load a lengthy webpage with various backgrounds that change according to the vertical scroll value?

I have been given a design that is 960px wide and approximately 7000px tall, divided into five segments stacked vertically at random points. There is a fixed sidebar that scrolls to each segment when a navigation link is clicked. The layout includes slider ...

Conceal a specific DIV class when another class is visible

In my WordPress project, I am working on a customization where the add to cart button on the product page should remain hidden until the customer answers all the questions. The plugin I am using offers options for the customers to select, such as Step 1, S ...

Checking the efficiency of Graphql API

Currently, I am in the process of optimizing key features within my Node.js API which incorporates GraphQL. This API serves as a proxy, receiving requests from various sources and forwarding them to multiple APIs based on the request. I am interested in ...

Why do I keep receiving values only from the initial form? What could be the issue?

I am facing an issue on my website with multiple forms. The problem arises when the "Save" button is clicked, as it continues to check the fields in the first form instead of the form where the button is located. Here is a snippet of my current Ajax scrip ...

What is the best method for eliminating duplicate objects in an array using 2 specific properties?

I am currently dealing with an array of room objects and my task involves removing duplicate objects based on their room_rate_type_id property: const rooms = [{ room_rate_type_id: 202, price: 200 }, { room_rate_type_id: 202, price: 2 ...

When working with TypeScript, how do you determine the appropriate usage between "let" and "const"?

For TypeScript, under what circumstances would you choose to use "let" versus "const"? ...

Resetting the form and validation in AngularJS post form submission

I need help resetting a form and all validation messages after submission. Check out my code on plunker: http://plnkr.co/edit/992RP8gemIjgc3KxzLvQ?p=preview Here is the code snippet: Controller: app.controller('MainCtrl', function($scope) { ...

Unable to create module instance, despite correct module definition

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="../angular/angular-1.6.7/angular.js"/> <script src="../angular/angular-1.6.7/angular-route.min.js"/> <!--script type="text/ja ...