Skip to content
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

DatePicker日期选择:选择日期还没点击确定,底部的值已经更新,点击取消并没有取消选中的值 #845

Open
seeleyz opened this issue Jul 20, 2022 · 0 comments

Comments

@seeleyz
Copy link

seeleyz commented Jul 20, 2022

Version

6.0.0

Environment

组件示例

Reproduction link

https://stackblitz.com/run?file=src%2Fapp%2Fapp.component.ts

Steps to reproduce

import { Component, ViewEncapsulation } from '@angular/core';

@component({
selector: 'demo-date-picker-date',
encapsulation: ViewEncapsulation.None,
template: <List [className]="'date-picker-list'"> <ListItem DatePicker [extra]="currentDateFormat(value, 'yyyy-mm-dd')" [arrow]="'horizontal'" [mode]="'date'" [(ngModel)]="value" (onOk)="onOk($event)" > Date <Brief>{{ name }}</Brief> </ListItem> </List>,
styles: [
.date-picker-list .am-list-item .am-list-line .am-list-extra { flex-basis: initial; }
]
})
export class DemoDatePickerDateComponent {
name = '选择';
value = new Date();

currentDateFormat(date, format: string = 'yyyy-mm-dd HH:MM'): any {
const pad = (n: number): string => (n < 10 ? 0${n} : n.toString());
return format
.replace('yyyy', date.getFullYear())
.replace('mm', pad(date.getMonth() 1))
.replace('dd', pad(date.getDate()))
.replace('HH', pad(date.getHours()))
.replace('MM', pad(date.getMinutes()))
.replace('ss', pad(date.getSeconds()));
}

onOk(result: Date) {
this.name = this.currentDateFormat(result, 'yyyy-mm-dd');
this.value = result;
}

formatIt(date: Date, form: string) {
const pad = (n: number) => (n < 10 ? 0${n} : n);
const dateStr = ${date.getFullYear()}-${pad(date.getMonth() 1)}-${pad(date.getDate())};
const timeStr = ${pad(date.getHours())}:${pad(date.getMinutes())};
if (form === 'YYYY-MM-DD') {
return dateStr;
}
if (form === 'HH:mm') {
return timeStr;
}
return ${dateStr} ${timeStr};
}
}

What is expected?

选择了日期点击确定才赋值

What is actually happening?

还没点确定,关闭选择窗口已经赋值了

Other?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant