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

Mas warning on console The mask "__/__/____ __:__ _M" you passed is not valid for the format used P p. Falling down to uncontrolled not-masked input. #1776

Closed
activebiz opened this issue May 15, 2020 · 13 comments · Fixed by #1991
Labels
important Need work

Comments

@activebiz
Copy link

activebiz commented May 15, 2020

Environment

Tech Version
@material-ui/pickers 4.0.0-alpha.7
material-ui 4.9.14
TypeScript
React 16.12.0
Browser Chrome
Peer library "date-fns": "2.13.0"

Steps to reproduce

Code sandbox example: https://codesandbox.io/s/hungry-bohr-ugb2e?file=/src/App.js
Use basic example from the website.

Expected behavior

Not expecting any warnings from the example

Actual behavior

Mask warning on console "The mask "//____ : _M" you passed is not valid for the format used P p. Falling down to uncontrolled not-masked input. "
image

Live example

Code sandbox example: https://codesandbox.io/s/hungry-bohr-ugb2e?file=/src/App.js

@Philipp91
Copy link
Contributor

I think the relevant code is here. I'll send a fix.

@Philipp91
Copy link
Contributor

Philipp91 commented May 21, 2020

@dmtrKovalenko There are 4 other occurrences of \|\|.* \? in the code base. It's trivial to fix them (just put parentheses around the ternary expression), but I'm confident to fix them, as they might actually break things instead of fixing them, assuming that the current code has been tested as is.

Filed #1803 for those.

@Philipp91
Copy link
Contributor

Philipp91 commented May 22, 2020

This error message comes from this check that essentially ensures that the provided mask is one of two allowed masks, both of which can be derived from the format using only the utils. Yet the library hard-codes

https://github.com/mui-org/material-ui-pickers/blob/bffad8fce6bbd6e2e50badd3f66489f49e7d6a3a/lib/src/DateTimePicker/DateTimePicker.tsx#L78

masks for the en-US locale as default values. So if he user has a locale with a different date format, the library's default values are invalid by the library's own validation function.

Given that the validation function knows exactly what it wants (it's not like it tests a regex or does sanity checks, it literally has the exact expected value there), I propose to just make the more sensible of these two allowed values the default value. (If users want to switch to the other one, then they can still do so by overriding the prop.)

Philipp91 added a commit to Philipp91/material-ui-pickers that referenced this issue May 22, 2020
oliviertassinari pushed a commit to Philipp91/material-ui-pickers that referenced this issue May 22, 2020
oliviertassinari pushed a commit to Philipp91/material-ui-pickers that referenced this issue May 25, 2020
dmtrKovalenko pushed a commit that referenced this issue May 25, 2020
* Fix ternary condition for default mask values #1776

* add test case

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
@oliviertassinari
Copy link
Member

@dmtrKovalenko What do you think of the solution proposed by @Philipp91 in #1776 (comment)?

@oliviertassinari oliviertassinari added the important Need work label Jun 6, 2020
@Miyagee
Copy link

Miyagee commented Jun 16, 2020

I'm getting the warning the mask "__. ____ ____" you passed is not valid for the format used dd. MMMM yyyy. Falling down to uncontrolled not-masked input. I guess it is related to this issue?

@hatamsoyunov
Copy link

My date format DD.MM.YYYY and I added mask.

<DateRangePicker
    mask="__.__.____"
    ...
/>

@gReis89
Copy link

gReis89 commented Jun 25, 2020

I'm trying to use DateRangePicker with a custom inputFormat, the format works pretty good, but the mask is breaking, I got the same warning message from this topic:

The mask "__/__/____" you passed is not valid for the format used YYYY-MMM-DD. Falling down to uncontrolled not-masked input. 

Live example

I tried to add a mask="____-___-__" prop to follow my inputFormat but I got the same error.

@oliviertassinari
Copy link
Member

@Philipp91 After further internal discussion, it came up that the reason this warning has to exist is because of the variable length of some of the parts of the date. Basically, in the US, 7:00 is as much valid as 17:00. In order to account for this variable length, we would need a logic close to https://codesandbox.io/s/ecstatic-germain-jw5fr?file=/index.js, which might add too much complexity than the problem is worth.

In this context, a possible option is to give up on the localized format, for instance, https://github.com/dmtrKovalenko/date-io/blob/7bf469805c1fd73d072164c71d3a3267fcc42ce7/packages/date-fns/src/date-fns-utils.ts#L45 https://date-fns.org/v2.14.0/docs/format, and hard code the format to a full length version, meaning 07:00 instead of 7:00.

@Miyagee
Copy link

Miyagee commented Jul 13, 2020

Any updates on this one @oliviertassinari?

@Miyagee
Copy link

Miyagee commented Jul 17, 2020

Still getting the warning even after 4.0.0-alpha.9 The mask "__. ____ ____" you passed is not valid for the format used dd. MMMM yyyy. Falling down to uncontrolled not-masked input.

@dmtrKovalenko
Copy link
Member

It was not released. Will be released today as alpha.10

@BowlingX
Copy link

BowlingX commented Jul 17, 2020

The mask is not working for __/__/____ __:__ _M in alpha.10 (and the DateTimePicker) for me now with the en-us locale. Masks basically just work when I disable ampm. German works fine, for example. (see https://codesandbox.io/s/peaceful-bash-2jmu3?file=/src/App.jsx)

@oliviertassinari
Copy link
Member

@BowlingX what you are describing sounds expected. It's the tradeoff highlighted in #1776 (comment). If you wish to explore the path of a smart mask, feel free to :). I wouldn't expect it to require too many lines of codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
important Need work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants