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

How to clear DateTime field? #2358

Closed
dmitriytretyakov opened this issue Feb 17, 2020 · 26 comments
Closed

How to clear DateTime field? #2358

dmitriytretyakov opened this issue Feb 17, 2020 · 26 comments
Labels
bug Verified bug by the Nova team
Milestone

Comments

@dmitriytretyakov
Copy link

I try to delete value from input and then click out of the field, system add some default value to field, how can i clear field?

@ziming
Copy link

ziming commented Feb 17, 2020

It's a known bug currently.

@deckchan
Copy link

@davidhemphill

Will you consider to make a "Clear" button to clear the field?

We sometimes define a field "valid_until" that allow user input empty value which is the meaning of "forever".

This bug is quite bothering.
Appreciate if you can handle this.

@zachgarcia1
Copy link

It seems if you set it to a date field you can clear it but date time won't let you.

@ziming
Copy link

ziming commented Mar 2, 2020

Also is that it doesn't default to current date time value, only to current date value

@jbrooksuk
Copy link
Member

I'm able to empty out a DateTime field, just by clearing its contents:

Kapture 2020-03-03 at 12 49 17

@ziming
Copy link

ziming commented Mar 3, 2020

@jbrooksuk

After clearing the datetime field did you try to click on another field or elsewhere in the background?

Or did you just go to click Update Post right away?

Because I just tested it again after your comment and the value go back if i click on another field or the background. And I'm on the latest nova version.

@zachgarcia1
Copy link

yea it doesn't look like @jbrooksuk is on the latest version i'm currently using 2.12.0

@jbrooksuk
Copy link
Member

After clearing the datetime field did you try to click on another field or elsewhere in the background?

Or did you just go to click Update Post right away?

Because I just tested it again after your comment and the value go back if i click on another field or the background. And I'm on the latest nova version.

I shall look at this now.

yea it doesn't look like @jbrooksuk is on the latest version i'm currently using 2.12.0

I only just released v2.12.0 😂

@zachgarcia1
Copy link

yep just sharing my version updated today @jbrooksuk

@zachgarcia1
Copy link

zachgarcia1 commented Mar 3, 2020

sorry for the slow erasing of fields just trying to show what i've been experiencing, and then like I said up top with the date field this will remove the value once its been set, it seems to only be an issue with the date time field

datetime-field

@dmitriytretyakov
Copy link
Author

Yes, it's actual only for DateTime, my version is 2.12.0 and bug exists

@zachgarcia1
Copy link

@jbrooksuk where you able to reproduce this issue?

@michielkempen
Copy link

I'm currently on Laravel Nova v3.0.2 and I can confirm that this is a bug.

Screen-Recording-2020-03-08-at-18 00 57

@michielkempen
Copy link

Hey @jbrooksuk @davidhemphill, I spent some time debugging this issue and came up with a solution.

There seem to be a few open issues on the flatpickr repository regarding this problem, but no clear solution. However, the problem can be easily overcome in Nova by applying the following changes to the resources/js/components/DateTimePicker.vue file.

<template>
  <input
    :disabled="disabled"
    :class="{ '!cursor-not-allowed': disabled }"
+   @keyup.delete="onClear"
    :value="value"
    ref="datePicker"
    type="text"
    :placeholder="placeholder"
  />
</template>

<script>
import flatpickr from 'flatpickr'
import 'flatpickr/dist/themes/airbnb.css'

export default {
  props: {
    ...
  },

  data: () => ({ flatpickr: null }),

  mounted() {
    this.$nextTick(() => {
      this.flatpickr = flatpickr(this.$refs.datePicker, {
        enableTime: this.enableTime,
        enableSeconds: this.enableSeconds,
        onClose: this.onChange,
        onChange: this.onChange,
        dateFormat: this.dateFormat,
        allowInput: true,
        // static: true,
        time_24hr: !this.twelveHourTime,
        locale: { firstDayOfWeek: this.firstDayOfWeek },
      })
    })
  },

  methods: {
    onChange(event) {
      this.$emit('change', this.$refs.datePicker.value)
    },
+   onClear(event) {
+     if(event.target.value === '') {
+       this.flatpickr.close();
+     }
+   }
  },

  beforeDestroy() {
    this.flatpickr.destroy()
  },
}
</script>

<style scoped>
.\!cursor-not-allowed {
  cursor: not-allowed !important;
}
</style>

The resulting workflow is as follows:

  1. You can deselect/select a datetime as before.
  2. Once you clear the input field using backspace or delete, the field is cleared and the datepicker is closed.

test

Any chance you could verify the solution and apply the fix?

Thanks in advance!

@jbrooksuk
Copy link
Member

@michielkempen this didn't work for me using Super+Del.

@jbrooksuk
Copy link
Member

However, it works if I select all and then delete, but that's only one way to delete it.

@dmitriytretyakov
Copy link
Author

However, it works if I select all and then delete, but that's only one way to delete it.

It's doesn't works for me

@deckchan
Copy link

How about make a "Clear" button, no matter on calendar or under the field?
Delete the text on a calendar field is not the obvious way, IMO.

And this approach should have no more arguing on deleting the text is work or not.

@dmitriytretyakov
Copy link
Author

What about fix?

@zachgarcia1
Copy link

still not working on v3.1.0

@ruslansteiger
Copy link

There is a workaround in the meantime #2344 (comment) @dmitriytretyakov @zachgarcia1

It is working for me 🙏

@davidraijmakers
Copy link

This is still occuring

@dmitriytretyakov
Copy link
Author

Please fix this

@zachgarcia1
Copy link

still not working on v3.2.1

@jbrooksuk jbrooksuk added the bug Verified bug by the Nova team label Apr 7, 2020
@jbrooksuk jbrooksuk added this to the v3.x milestone Apr 7, 2020
@jbrooksuk
Copy link
Member

Locking as we know this is a bug and is not yet fixed.

@laravel laravel locked and limited conversation to collaborators Apr 7, 2020
@davidhemphill
Copy link
Contributor

Fixed via laravel/nova#907

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

9 participants