Tips for manually inputting dates in Primeng Calendar Datepicker with the slash "/" symbol

I need assistance with adding slashes to manual input when using the primeng Calendar component.

<p-calendar
   [monthNavigator]="true"
   [yearNavigator]="true"
   yearRange="1950:2021"
   ngModel
   [required]="true" 
   [maxDate]='today'
   [showOnFocus]="false"
   id="date1"
   [showIcon]="true"
   name="date1"
   inputId="date1"
   placeholder="Date Of Birth">
</p-calendar>

Answer №1

Slashes are already supported in PrimeNG calendar.

If you are experiencing issues with slashes not displaying correctly, it might be due to the calendar date format settings. Make sure to explicitly set the desired format as shown below:

<p-calendar 
  [monthNavigator]="true" 
  [yearNavigator]="true" 
  yearRange="1950:2021" 
  ngModel  
  [required]="true" 
  [maxDate]='today' 
  [showOnFocus]="false" 
  id="date1" 
  [showIcon]="true"  
  name="date1" 
  inputId="date1" 
  placeholder="Date Of Birth" 
  dateFormat="dd/mm/yy">
</p-calendar>

-- Edit --

If you are looking for a date mask feature in PrimeNG calendar, please note that it is currently not supported. A request has been submitted regarding this issue in February 2020, you can track its progress here.

In the meantime, you can utilize other date mask libraries like racoon-mask. For example:

npm install --save racoon-mask

app.module.ts

import {PrimeNgCalendarMaskModule} from 'racoon-mask'
...
...
imports:      [ ..., CalendarModule, PrimeNgCalendarMaskModule ]

app.component.html

<p-calendar 
  [monthNavigator]="true" 
  [yearNavigator]="true" 
  yearRange="1950:2021" 
  ngModel  
  [required]="true" 
  [maxDate]='today' 
  [showOnFocus]="false" 
  id="date1" 
  name="date1" 
  inputId="date1" 
  placeholder="Date Of Birth" 
  dateFormat="dd/mm/yy"
  rPCalendarMask>
</p-calendar>
<p>

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

Employing the ngFor directive, insert two elements onto a single row, then proceed to generate a fresh

For some time now, I've been attempting to loop through an array of objects using *ngFor and place two elements inside each row. The goal is to generate a new row after every two components have been added. Here's what I've attempted so far ...

Creating Personalized Validators for Angular Version 5 Reactive Forms

I am struggling to create a custom validator for my Angular v5 application. I followed the documentation for a basic password match example in the Docs, but it's not working as expected. this.personalInfoForm = _fb.group({ 'name': [null,V ...

Interact with DOM elements and manipulate TypeScript data

I am looking to display a list of IDs by fetching them from my database. Within my ngfor loop, I have included a child component. Is there a way to access each ID within each child component? I would like to retrieve the value of "GameToDisplay.key" in pl ...

Using Angular Ngrx to Retrieve and Showcase a Selection of Choices from a Java API

When accessing the Java API at localhost://company/products/123/fetchOptions, you can expect a response similar to the following: { "Increase": true, "Decrease" : true, "Like" : true, "Dislike" : true, "Old" : false, "Others" : true } Using Angula ...

What is the most effective way to code and define a MatSelect's MatSelectTrigger using programming techniques?

How can I programmatically set the MatSelectTrigger template for a MatSelect instance using the provided reference? The documentation mentions a settable customTrigger property, but information on the MatSelectTrigger class or how to create one dynamically ...

Troubleshooting an Issue with MediaStreamRecorder in TypeScript: Dealing with

I've been working on an audio recorder that utilizes the user's PC microphone, and everything seems to be functioning correctly. However, I've encountered an error when attempting to record the audio: audioHandler.ts:45 Uncaught TypeError ...

Angular 2 form controls featuring custom display names and unique values

As I work on developing a form, I have encountered the need to display something different than the content itself. Here's what I currently have in my code: <ion-label>Rate</ion-label> <ion-input text-right detail-push formContro ...

How to immediately set focus on a form control in Angular Material without needing a click event

Currently working with Angular 9 and Material, we have implemented a Stepper to assist users in navigating through our workflow steps. Our goal is to enable users to go through these steps using only the keyboard, without relying on mouse clicks for contro ...

Angular service: Issue with updating value in observable property

Attempting to establish communication between two browser tabs/windows using the BroadcastChannel API. The communication appears to work between two instances of an angular service, but changes to the observable values are not reflected. I am attempting to ...

Creating dynamic elements in Angular2 componentsIn Angular2, you can seamlessly

Utilizing the Google Maps JavaScript API in my project, I faced the challenge of displaying an Angular component within an InfoWindow. After loading the Google Maps API with the Jsonp service, I had access to the google.maps.Map object. In a component, I ...

Accessing files from various directories within my project

I'm working on a project with 2 sources and I need to import a file from MyProject into nest-project-payment. Can you please guide me on how to do this? Here is the current file structure of my project: https://i.stack.imgur.com/KGKnp.png I attempt ...

What are the benefits of reverting back to an Angular 1 directive instead of using an Angular 2 application

Our team has created numerous Angular 1 components and is eager to incorporate them into our Angular 2 application. However, the documentation suggests that we must downgrade the Angular 2 application in order to integrate and utilize the Angular 1 direc ...

Is there a way to reset static data in a TypeScript subclass? (or alternative method for managing global data)

I have a particular set of static data that I would like to access through an API using basic logic. Specifically, this data pertains to metadata about Java classes. My approach involved incorporating the API into a few static methods within a class, alon ...

Issue with font-size changes using css variables in Angular not updating in browser for specific fields

Utilizing CSS variables, I have implemented a feature that allows users to adjust the font size to small, medium, or large. While this functionality works correctly for most fields, there are certain instances where the value is applied but not displayed. ...

ngOnInit unable to properly listen to event stream

I've been trying to solve a persistent issue without success. The problem involves the interaction between three key elements: the HeaderComponent, TabChangingService, and TabsComponent. Within the HeaderComponent, there are three buttons, each with a ...

Creating Instances of Variables Within a Class

Currently, I am working on a project using Ionic and Angular. I have come across various ways of instantiating variables and I'm unsure about the implications of each method. Here are three scenarios that confuse me: export class someClass { myVaria ...

Vue 3 Electron subcomponents and routes not displayed

Working on a project in Vue3 (v3.2.25) and Electron (v16.0.7), I have integrated vue-router4 to handle navigation within the application. During development, everything works perfectly as expected. However, when the application is built for production, the ...

How can you apply an active class using React-Router?

My React-Router navigation issue nav.tsx import React from 'react' import { menu } from './menu' import { Link } from 'react-router-dom' import styles from './HamburgerMenu.module.scss' const HamburgerMenu: React.F ...

Creating and handling Observable of Observables in RxJS: Best practices

Within my Angular application, there are multiple services that have dependencies on each other. To manage this, I have created a dependency map as shown in the example below: let accountInitialization$: Observable<void>; let productInitialization$: ...

The interface does not allow properties to be assigned as string indexes

Below are the interfaces I am currently working with: export interface Meta { counter: number; limit: number; offset: number; total: number; } export interface Api<T> { [key: string]: T[]; meta: Meta; // encountered an error here } I h ...