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

Mastering Angular Service Calls in TypeScript: A Comprehensive Guide

In the midst of my TypeScript angular project, I am aiming to revamp it by incorporating services. However, I have encountered an issue where when calling a function within the service, the runtime does not recognize it as the service class but rather the ...

Emphasize the designated drop zone in Dragula

Incorporating the Dragula package into my Angular 2 project has greatly enhanced the drag-and-drop functionality. Bundling this feature has been a seamless experience. Visit the ng2-dragula GitHub page for more information. Although the drag-and-drop fun ...

"Error message: Trying to import a component in Angular, but encountering a message stating that the component has no exported

When creating a component named headerComponent and importing it into app.component.ts, an error is encountered stating that 'website/src/app/header/app.headerComponent' has no exported member 'headerComponent'. The code for app.headerC ...

Steps for setting up the 'node_modules' folder in an older Angular project using the 'npm install' command

Currently, I am in the process of transferring our project code from our repository to a new laptop. The project was initially developed on Angular 5 last year. However, the new laptop is equipped with the latest versions of Angular CLI, NodeJS, and NPM to ...

typescript error is not defined

While browsing online, I came across a post discussing how to transfer data from an MVC model to a .ts file. The suggestion was to include the following code: <script type="text/javascript"> var testUrl = @Html.Raw(Json.Encode(Model.testUrl) ...

ngFor loop is not displaying the correct values from the JSON object

Having some trouble making a REST call and displaying the results obtained. I've managed to successfully work with a simpler JSON data structure, but I'm struggling to get ngFor to properly process this particular data structure. I've tried ...

Converting Objects to Arrays with Angular Observables

After searching extensively on SO for answers regarding item conversions in Javascript/Angular, I couldn't find a solution that addresses my specific problem. When retrieving data from Firestore as an object with potential duplicates, I need to perfor ...

Two-way conditional type mapping

Currently, I am working on mapping the various "data types" of an object to a corresponding "schema" type. If the property's data type is boolean, it should be mapped to the "BooleanComponents" type The code snippet below demonstrates how this can ...

Error: JavaScript object array failing to import properly

In my code, I have an array of objects named trace which is defined as follows: export const trace: IStackTrace[] = [ { ordered_globals: ["c"], stdout: "", func_name: "<module>", stack_to_render: [], globals: { c: ["REF" ...

What is the best way to implement an Angular application within the child routes of another Angular application?

Is it possible to load an Angular app using lazy-loading (when a specific route is hit by users) into another Angular app without compiling the first one for use in the second? This is the Routing-Module of the app to nest into an Angular app: const upgr ...

What are the steps to switch out the 'subscribe' method with 'mergeMap' or

I am trying to understand how I can replace the subscribe method with switchMap in my code. I have been searching for an example online but haven't found one yet. dialogRef.afterClosed().pipe(filter(result => !!result)).switchMap(result => { ...

Unable to run unit tests on project using my custom React library

If any of you have encountered this issue or know how to solve it, please help me. I created an NPM package that can be found at https://www.npmjs.com/package/@applaudo/react-clapp-ui It installs and runs smoothly in other projects using create react app; ...

Develop a customized interface for exporting styled components

I am struggling to figure out how to export an interface that includes both the built-in Styled Components props (such as as) and my custom properties. Scenario I have created a styled component named CustomTypography which allows for adding typographic s ...

Having trouble accessing the theme in a styled component with @emotion/styled

https://i.stack.imgur.com/zHLON.png I've been using @emotion/react for theming and successfully injected the theme into it. I can access the theme using useTheme within components, but I'm facing some difficulties in accessing the theme within s ...

Experimenting with a function that initiates the downloading of a file using jest

I'm currently trying to test a function using the JEST library (I also have enzyme in my project), but I've hit a wall. To summarize, this function is used to export data that has been prepared beforehand. I manipulate some data and then pass it ...

What is the correct way to effectively share data between components using a service?

I've been diving into learning Angular 2 and successfully implemented data sharing between sibling components using input/output functions. Check out my working example here. // Our root app component import {Component, NgModule} from '@angular ...

Strict type inference for the number data type in TypeScript

I am interested in inferring the number type within this function: type Options = { count: number }; function bar<C extends Options>(options: C): C['count'] extends 3 ? 'x' : 'y' {} bar({ count: 3 }) // x bar({ count: ...

When incorporating a JS React component in TypeScript, an error may occur stating that the JSX element type 'MyComponent' is not a valid constructor function for JSX elements

Currently, I am dealing with a JavaScript legacy project that utilizes the React framework. Within this project, there are React components defined which I wish to reuse in a completely different TypeScript React project. The JavaScript React component is ...

Angular 2.0's development of modules and implementation of shadow DOM focuses on supporting a left

My website supports "right to left" languages like Arabic. When the language is Arabic, I add the dir="rtl" attribute to the body tag. This aligns all inline positioned children from the right side, even within custom components. Now, I want a custom styl ...

The element in Selenium's net.serenity.bdd.core.exceptions.SerenityManagedException has encountered a timeout issue

I'm having difficulty choosing a radio button on this particular form: <form _ngcontent-c4="" novalidate="" class="ng-untouched ng-pristine ng-invalid"> <div _ngcontent-c4="" class="text-center"> <div _ngcontent-c4="" class=" ...