-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Popup datepicker with custom date picking function closes automatically after value select #1984
Comments
@maxokorokov would you mind having a look? |
Yep, by default the popup is closed when the date is selected, because of this subscription. We currently don't have a dedicated range picker; I'm not sure how you want to handle Maybe it would be easier to put Otherwise looks like a valid request for me:
|
The least invasive solution would seem to be to add a flag to the API (ex: // date selection event handling
this._cRef.instance.registerOnChange((selectedDate) => {
this.writeValue(selectedDate);
this._onChange(selectedDate);
if (this.autoClose) {
this.close();
}
}); This would keep backwards compatibility intact and allow users to control when the popup is closed when needed. |
@lbrooks Yeah, I also thought to do that; because of the backwards compatibility. |
In conjunction with this, it would probably be best to allow customization of the input's label text. this._renderer.setElementProperty(this._elRef.nativeElement, 'value', this._parserFormatter.format(model)); Perhaps it could be as simple as adding a function input? (currentSelection: NgbDate, parserFormatter: NgbDateParserFormatter): string => { ... } The default value would be: (currentSelection: NgbDate, parserFormatter: NgbDateParserFormatter): string => parserFormatter.format(currentSelection); Users would be defining this function in an area that they would have access to all dates selected, so there would be no need to add that complexity to the function or the input class itself |
Just wanted to add a very simple example of the implementing code: @ViewChild('datePicker') datePicker: NgbInputDatepicker;
fromDate: NgbDate;
toDate: NgbDate;
onFirstSelection = true;
selectDate(date: NgbDate) {
if(this.onFirstSelection){
this.fromDate = date;
this.onFirstSelection = false;
} else {
this.toDate = date;
this.onFirstSelection = true;
this.datePicker.close();
}
}
formatInputText(currentSelection: NgbDate, parserFormatter: NgbDateParserFormatter) {
return `${this.fromDate ? parserFormatter.format(this.fromDate) : ''} - ${this.toDate ? parserFormatter.format(this.toDate) : ''}`;
} <div class="date-picker-wrapper">
<input class="form-control" placeholder="yyyy-mm-dd" name="dp" ngModel ngbDatepicker #datePicker="ngbDatepicker" (ngModelChange)="selectDate($event)" [dayTemplate]="t" [autoClose]="false" (formatLabel)="formatInputText($event.date, $event.parser)">
<ng-template #t let-date="date" let-focused="focused">
<span class="custom-day"
[class.range]="isDateFrom(date) || isDateTo(date) || isDateInside(date) || isDateHovered(date)"
[class.faded]="isDateHovered(date) || isDateInside(date)"
(mouseenter)="hoveredDate = date"
(mouseleave)="hoveredDate = null">
{{ date.day }}
</span>
</ng-template>
</div>
<button class="input-group-addon" (click)="datePicker.toggle()" type="button">
<span class="ln-icon-triangle-down"></span>
</button> |
any workaround or update on this? |
I am also experiencing this issue. Would love to just have it close when endDate doesnt equal null if endDate is available. |
Could anybody please review the changes in #2192? <input ngbDatepicker #d="ngbDatepicker" [autoClose]="false"
ngModel (ngModelChange)="onDateChange($event, d)"> You can call P.S. I'll also introduce the |
+1 for supporting |
I found workaround by overloading datepicker-input.js.
Third - correct NgbInputDatepicker.prototype._writeModelValue [line 264]: Finally - component.ts:
component.html:
As you can see, my formatted date value is passed through a variable headerLabel: |
$("#datetimepicker1").click(function () { |
Bug description:
Popup datepicker with custom date picking function closes automatically after value select even with preventing event from propagation etc. I think there should be an option to prevent closing datepicker on date select (e.g. if I want to implement range datepicker in popup its problematic).
Link to minimally-working plunker that reproduces the issue:
http://plnkr.co/edit/McF4tVd9D2fXNNx9QQxe?p=preview
Version of Angular, ng-bootstrap, and Bootstrap:
Angular: 4.1.3
ng-bootstrap: 1.0.0-beta.2
Bootstrap: 4.0.0-beta
The text was updated successfully, but these errors were encountered: