1

I have an Angular2 application with PrimeNG suite installed.

I need to implement a form with two input elements and use in order to manage two date values.

I tried to use InputMask applying a specific mask and it works, now I don't know how to covert the date from Italian format ( provided by the user ) to TypeScript/Javascript format in order to be able to post the data...

The code I have implemented is this:

<p-inputMask mask="99/99/9999" [(ngModel)]="offert.dateDelivery" formcontrolname="dateDelivery" placeholder="dd/mm/yyyy" [ngModelOptions]="{standalone: true}" slotChar="dd/mm/yyyy"></p-inputMask>

The property offert.dateDelivery binds a Date field of a class.

The problem is that the user is forced to insert the value in Italian format ( dd/mm/yyyy ) that is actually not acceptable as date from Javascript/Typescript function...

How can I manage this scenario ?

thanks

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
DarioN1
  • 2,460
  • 7
  • 32
  • 67
  • 1
    so the user inputs this string `22/05/2009` and that works fine but you need to convert the string `22/05/2009` to a javascript `Date` object? or do you need to convert it to a very specific format ? – Ahmed Musallam Apr 28 '17 at 18:27
  • yes bro, that is what I need – DarioN1 Apr 28 '17 at 18:34
  • click on the PrimeFaces tag in your question. Read it... are you using that? And no need to add relevant tags in the title – Kukeltje Apr 28 '17 at 20:38

1 Answers1

2

I solved the problem by binding two different independents string variables and parsing them to the two date properties after user click... The solution is easiest than expected

DarioN1
  • 2,460
  • 7
  • 32
  • 67