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.

Mobile support incompatible with jQuery Validation

See original GitHub issue

[NOTE: This is probably more for the docs or as a gotcha for anyone else who might experience this issue with the popular validation plugin.]

When Flatpickr detects a mobile it’s default action is to fallback to use the native datetime picker along with changing type attribute for the original input element from text to hidden and then inserting a new input element with the type attribute set to date (or time, depending on your usage I guess).

<input type="hidden" name="dob" class="date flatpickr-input" readonly="readonly" aria-required="true">
<input class="date required flatpickr-input flatpickr-mobile" step="any" tabindex="1" type="date" max="2017-07-18" aria-required="true">

The inclusion of the step attribute on the newly inserted input date type is where jQuery Validation chokes with:

Uncaught Error: Step attribute on input type date is not supported.

If you refer to the jQuery Validation (v1.16.0) L1432 of the library you’ll see it only has support for the step attribute where the input has a type attribute equal to either text, number or range. L1455 indicates support for types date, datetime, datetime-local, month, time and week is still on the way.

Workaround

At the moment, I’m using a workaround which is to use the onClose callback to remove the step attribute altogether:

{
  onClose: function (selectedDates, dateStr, instance) {
    if (instance.isMobile) {
      $('form input[type="date"][step="any"]').removeAttr('step');
    }
  }
}

The alternative, is forcing the unrecommended option of forcing the use of the non-native picker even on mobile:

{
  disableMobile: true
}

I’m posting this to get some feedback as to whether there is a better way to achieve harmony between these two libraries so they’ll play nice together.

Other routes might be to add an option to omit the step attribute for mobiles unless one exists on the input already in Flatpickr or at least until jQuery Validation gets round to adding support for the step attribute in relation to datetime input types.

Reproduction Link

https://jsfiddle.net/jfkpqsk3/

Your Environment

  • flatpickr version used: 3.0.6
  • Browser name and version: Browser (Default, Chrome WebView 59), Chrome (59.0.3071.125)
  • OS and version: Android 6.0.0; Elephone S7

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
jongbelegencommented, Dec 17, 2018

Nice solution would be:

onReady: function(selectedDates, dateStr, instance){
  if (instance.isMobile) {
    $(instance.mobileInput).attr('step', null);
  }
},
2reactions
chmlncommented, Jul 21, 2017

Hello @Dreyer

Thanks for the note. This seems more like an issue with jquery validation than flatpickr itself.

The only thing I’d perhaps recommend is using onReady instead of onClose as you only need to remove the attribute once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Validate plugin not working for phone number
1 Answer 1 ... This is more like what you should be doing. (Note how your ajax() belongs inside of the submitHandler .)...
Read more >
Best Tips for Troubleshooting jQuery Validation - Robert Half
Check out our top jQuery Validation troubleshooting suggestions that can save you both time and frustration.
Read more >
Documentation - jQuery Validation Plugin
method: A validation method implements the logic to validate an element, like an email method that checks for the right format of a...
Read more >
Form validation | Can I use... Support tables for HTML5, CSS3 ...
Method of setting required fields and field types without requiring JavaScript. This includes preventing forms from being submitted when appropriate, the ...
Read more >
jQuery Validation Plugin - OnClick and OnFocusOut conflict
Hi, I have an issue with form validation. I use jquery-1.11.2 and jquery.validate plugin. I also tried to update it to ...
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