简体   繁体   English

如何在 IonDateTime 中添加“CLEAR”按钮?

[英]How to add “CLEAR” button to IonDateTime?

The IonicDateTime component allows me to save or cancel the date picked. IonicDateTime 组件允许我保存或取消选择的日期。 However, I want to be able to clear the value chosen.但是,我希望能够清除选择的值。

I've looked for solutions and one of them was to use pickerOptions, but this overrides the existing buttons that I still need and I'm not certain how I can create the cancel button anyway or reproduce the existing save/cancel buttons.我一直在寻找解决方案,其中之一是使用pickerOptions,但这会覆盖我仍然需要的现有按钮,而且我不确定如何创建取消按钮或重现现有的保存/取消按钮。

Here's my code.这是我的代码。 FYI I'm using Ionic 4 with React.仅供参考,我将 Ionic 4 与 React 一起使用。

<IonItem>
     <IonLabel position="stacked">End date</IonLabel>
     <IonDatetime id="enddate" name="enddate"></IonDatetime>
</IonItem>

I have been searching for this as well and found the below:我也一直在寻找这个,并找到了以下内容:

<ion-datetime
formControlName="myDateCustom"
[pickerOptions]="customPickerOption"></ion-datetime>

and then in the TS:然后在 TS 中:

customPickerOption = {
buttons: [{
text: 'Clear',
   handler: () => this.myForm.controls['myDateCustom'].setValue(null)}]

Taken from the below link: https://javascriptio.com/view/1360708/add-button-clear-value-ion-datetime-in-ionic取自以下链接: https://javascriptio.com/view/1360708/add-button-clear-value-ion-datetime-in-ionic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM