NativeScript / nativescript-datetimepicker

Plugin with date and time picking fields
Apache License 2.0
27 stars 26 forks source link

How to clear/reset the component field? #65

Open baermathias opened 4 years ago

baermathias commented 4 years ago

I am using nativescript-vue and several <DatePickerField>'s in a filter/search. After clearing/resetting the filter I need it to show the hint text or an empty field.

When setting date to an empty string :date="''" the component shows the value 01.01.1970, so my method to clear it is by re-rendering the component and give each a key :key="keyVar1" with a random value this.keyVar1 = Math.random().toString(36).substring(2,15);.

Is there a more native method or is re-rendering the way to go here?

baermathias commented 4 years ago

I found out, that it is possible to pass undefined to date:

:date="undefined"

If this happens, the value of hint property will be shown preferred. Imo the same behaviour should happen with null and empty strings. Also this behaviour should be documented somewhere. So another solution can be to set hint to e.g. hint=" " and pass undefinded to date.

Maybe this info helps somebody.