Datepicker: can't set initual value using input & form control name
See original GitHub issueI can’t set the initial value of a datepicker that is bound to an input. Sample code:
//.html
<form [formGroup]="form" class="form-default">
<input type="text" class="form-control" formControlName="publishdate" ngbDatepicker #datepicker="ngbDatepicker">
</form>
<div class="input-group-addon" (click)="datepicker.toggle()"></div>
// ts
this.content.publishdate = new Date();
this.form.patchValue(this.content);
The input is not filled with the value from ‘content.publishdate’ and the datepicker when opened (through datepicker.toggle()) does not have the value from today. Is this correct? I didn’t find anythin in the docs about this.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Angular Reactive Form Can't assign default date value to ...
I am trying to assigned a custom date to the angular app datepicker, but no date value is showing.
Read more >Set Datepicker to null / empty throws error?
You need to set the default date using date picker input, not the mdb-datepicker component. Here is an example: HTML: <mdb-form-control> <input mdbInput ......
Read more ><input type="date"> - HTML: HyperText Markup Language
The date is formatted according to ISO8601, described in Date strings format. You can set a default value for the input with a...
Read more >Datepicker - Angular powered Bootstrap
By default the input is used as a target. Type: string | HTMLElement. Default value: - — initialized from NgbInputDatepickerConfig service.
Read more >Form Datepicker | Components - BootstrapVue
If <b-form-datepicker> has a value set for the name prop, a hidden input will be created which will have its name attribute set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I encountered the same problem. I fixed it by making sure that I’m passing in integers instead of strings:
You need to specify
publishdate
as an object (structure) with theyear
,month
andday
properties. Specifyingnew Date()
won’t work. See http://plnkr.co/edit/kj2TIP2b1DfTtWkuHFGA?p=preview and check https://ng-bootstrap.github.io/#/components/datepicker/examples for more examples.Closing as a support request.