question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

date_format not validating formats with timezones correctly

See original GitHub issue

Versions:

  • VueJs: 2.4.4
  • Vee-Validate: 2.0.0

Description:

I have a datepicker component that I use in my templates like this:

<datepicker 
       v-model="toDate" 
       v-validate="toDateValidator"
       name="To Date"
       data-vv-name="To date"
       :propClass="this.$validator.errors.has('To Date') ? 'input-validation-error' : ''"
       :propDate="toDate" 
       :includeTime="true" 
       @input="toDate = $event">
</datepicker>

the v-model property is a string that conforms to the default moment format: "YYYY-MM-DDTHH:mm:ssZ" which actually looks like "2017-11-08T19:00:00-08:00"

the v-validate object toDateValidator is defined like this:

get toDateValidator(): any {
       return {required: true, date_format: 'YYYY-MM-DDTHH:mm:ssZ', after: this.fromDate }
 }

When I call this.$validator.validateAll() the date_format validation passes correctly. I can change the date on the datepicker and again the date_format passes validation.

The issue I am faced with is if the utcOffset is changed to something different from what was set initially say "2017-11-09T16:00:00+13:00" the validation of the string will fail.

When the utcOffset is changed I have tried resetting the validator like so:

this.$validator.errors.clear();
this.$validator.reset();
this.$validator.pause();
setTimeout(() => {
      this.$validator.resume();
}, 400);

I can see the aria-invalid attribute equals false, but as soon as I call validateAll() it fails.

Is there something I’m doing wrong here.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tmacintoshcommented, Dec 3, 2017

Really appreciate the quick response and explanation. I might look into to replacing moment with date-fns but if that looks like too much work I’ll try creating a work around to use a Date object for the validation. However this has certainly helped. Thank you.

Edit: Using the extend method was actually the much easier solution. Thanks again.

0reactions
Erichaincommented, Feb 7, 2018

@tmacintosh Hello, I’m facing the similar problem.

I want to wapper the datepicker component and to show the error message when there an error occured:

<!-- MyDatepicker Component -->
<Datepicker
  :value="currentValue"
  :name="name"
  v-validate="validateRule"
/>

<span
  v-show="errors.has(name)"
>
  {{ errorMessage }}
</span>

Used like below:

<!-- Some page -->
<MyDatepicker
  error-message="some error occured!"
  name="myName"
  validate-rule="required:true"
/>

But when I invoke the validateAll method, it cannot trigger the validating, and therefore my error message won’t show.

So, could you please tell me how you solved this problem? Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Applying timezone to date format not working [duplicate]
As your are using java.util.date which have no Time Zone . It represent UTC/GMT no Time Zone offset. See below thing. so change...
Read more >
Working with dates and timezones in JavaScript - Ursa Health
A helpful primer for working with dates and timezones in Javascript. ... Not everything with a date actually happened at a moment in...
Read more >
9 Working with dates | The Epidemiologist R Handbook
%Z = Time zone (character). TIP: The format = argument of as.Date() is not telling R the format you want the dates to...
Read more >
DateTimeFormatter (Java Platform SE 8 ) - Oracle Help Center
This returns an immutable formatter capable of formatting and parsing a format that extends the ISO-8601 extended offset date-time format to add the...
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
Third-party library with expanded time zone and parsing support. ... An aware object represents a specific moment in time that is not open...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found