P-calendar / Date format

UI Components for Angular
Post Reply
Niiix
Posts: 18
Joined: 12 Oct 2017, 22:58

23 Oct 2017, 17:15

sudheer wrote:
23 Oct 2017, 12:46
You should create separate thread for different question....
ok ;)

Hello... Can you help plz :)

In component.html i have

Code: Select all

<form [formGroup]="dateForm" (ngSubmit)="onSubmit()">
	<div class="form-group">
		<p-calendar [(ngModel)]="dateValue" formControlName="date" id="float-input-calendar" dateFormat="dd.mm.yy"></p-calendar>
		{{dateValue|date}}
	</div>
	<button pButton type="button" (click)="onSubmit()" label="Result" class="ui-button-success"></button>
</form>
In component.ts

Code: Select all

[...]
dateForm: FormGroup;
dateValue: Date;

ngOnInit() {
    this.signupForm = new FormGroup({
          'date' : new FormControl(null),
          });


  onSubmit(){
        console.log(this.signupForm.value.date);
        }
So, after input calendar, I have
Image

And in console, I have
Image

How I can get the value in console, like a 26.10.2017 ?? (dd.mm.yy)

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

24 Oct 2017, 05:03

Check with Angular pipe usage in your component .ts file https://stackoverflow.com/questions/357 ... sing-pipes
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Niiix
Posts: 18
Joined: 12 Oct 2017, 22:58

25 Oct 2017, 15:45

Pipe it's a good way.
As I understand Pipe use for otput some information for user.
But if I need send some Date-information to server (http request) in format dd/mm/yyyy. <- here use Pipe, too?
Or mb use some cycle( For Each), for transform Thu Oct 26 2017 [...] to 26/10/2017

Phuluso
Posts: 1
Joined: 03 Mar 2020, 11:23

03 Mar 2020, 13:01

On your p-calendar tag try:

<div class="form-group">
<p-calendar [(ngModel)]="dateValue" formControlName="date" id="float-input-calendar" dateFormat="dd.mm.yy" #myCalendar></p-calendar>
{{dateValue|date}}
</div>
<button pButton type="button" (click)="onSubmit(myCalendar.inputFieldValue)" label="Result" class="ui-button-success"></button>

Your, onSubmit(calendarDate: any) {
console.log(calendarDate);
}

Hope you get the idea

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests