-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BsDatepickerConfig dateInputFormat doesn't work when patching values manually. #2809
Comments
Same problem, pls pls fix. |
Same problem here! Can it be fixed or done in other ways? |
Same problem when initialising and binding through |
Same problem here. Any update for this? Or a method to patch values using some internal method? |
I have the same problem. When I want to init the input with any value, the format is wrong. Only works when I select the date in the calendar. |
Badly need this fixed! Does someone have a workaround? |
This post suggests it not currently possible and a feature request needs submitting #2702 |
KrzysztofJaneczko - thanks! using this for now as a workaround. |
To fix this issue you have to add formControlName to the input like this. in component.ts import * as moment from 'moment';
import {BsDatepickerConfig} from 'ngx-bootstrap/datepicker';
import {defineLocale} from 'ngx-bootstrap/bs-moment';
import {fr} from 'ngx-bootstrap/locale';
[...]
public dpConfig: Partial<BsDatepickerConfig> = new BsDatepickerConfig();
constructor(private _formBuilder: FormBuilder) {
moment.locale('fr');
defineLocale('fr', fr);
this.Form = this._formBuilder.group({
startDate: [this.startDate, Validators.required],
endDate: [this.endDate, Validators.required]
});
this.dpConfig.containerClass = 'theme-blue';
this.dpConfig.locale = 'fr';
this.dpConfig.dateInputFormat = 'L'; // Or format like you want
} in component.html <div class="input-group" [formGroup]="Form">
<input class="form-control"
bsDatepicker
id="startDate"
type="text"
[bsConfig]="dpConfig"
formControlName="startDate"
value="{{ startDate | date: 'dd/MM/yyyy' }}"
[(ngModel)]="startDate">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
<div class="input-group" [formGroup]="Form">
<input class="form-control"
bsDatepicker
id="endDate"
type="text"
[bsConfig]="dpConfig"
formControlName="endDate"
[minDate]="minEndDate"
value="{{ endDate | date: 'dd/MM/yyyy' }}"
[(ngModel)]="endDate">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div> |
Yes this works! |
@alexisAvenel thank you! |
Any working workaround for template driven forms? Thanks, |
Above solution doesn't work for initial value? |
Yes @joaofsilva . :| |
The solution above works for initial value but typing new date in it still handles the input as mm/dd/yyyy. Anyone found a workaround for that case? |
the below steps will solve the issue
|
@konasunny This correctly formats an initial date or one selected from calendar according to selected locale, but when using the input field to type in a date its seems to only accept mm.dd.yyyy. You can test this behaviour in the locales example here https://valor-software.com/ngx-bootstrap/#/datepicker
|
Should not the typed-in date be parsed using provided date format from Instead of if (typeof value === 'string') {
const date = new Date(_locale.preparse(value));
this._value = isNaN(date.valueOf()) ? null :
} When I use @alexisAvenel solution I am still getting what @bendandi is describing (broken type in date format - not reflected in date picker). |
It depends on what kind of form we use |
Is this issue fixed for bsDateRangePicker? |
You set date format for value via config or bsConfig property |
@valorkin when you add mask DD/MM/YYYY and add date by the calendar for example 11/02/1985 it works but when changing to the year to 2000 it goes for 02/11/1985 so there is a issue on focus out, is putting to the format of MM/DD/YYYY, so the only way this is working is to add DD/MMM/YYYY |
So how should dateInputFormat work? I've have the following bsConfig on a daterangepicker
but it's still formatted as MM/DD/YYYY |
<input class="form-control" type="text" |
If you are using Date Range Picker then instead of "dateInputFormat" you should use "rangeInputFormat" in [bsConfig] . |
Bump |
@konasunny, thank you the above solution works for me import { BsDatepickerConfig } from 'ngx-bootstrap/datepicker'; |
Worked for me |
It worked for me. Thanks, @manmohanagarwal4! |
How to Fix Onchange Date after manually insert date date gets changed to different date. for example
it result different date. code
|
for me issue is still there with this.bsConfig.rangeInputFormat = 'MM/YY'; any work around for this. version - "ngx-bootstrap": "8.0.0" SolutionI found simple workaround for this. // get dateRangePicker Ref.
@ViewChild(BsDaterangepickerDirective) bsDaterangepicker: BsDaterangepickerDirective;
// call setConfig after setting bsConfig.
this.bsConfig.rangeInputFormat = 'MM/YY';
this.bsDaterangepicker.setConfig(); |
The DateInputFormatter works perfectly and displays the desired format when selecting the date through the datepicker but when I patch the value through the form like this:
this.form.patchValue({ date_begin: new Date() })
it stays with the default MM/DD/YYYY format.The datepicker:
bsDatepicker #d="bsDatepicker" [bsConfig]="{ dateInputFormat: 'DD-MM-YYYY' }"
Does anyone know a fix for this?
edit by @valorkin: solution #2809 (comment)
The text was updated successfully, but these errors were encountered: