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

[pickers] Datepicker with html5 validation #10274

Closed
2 tasks done
OZZlE opened this issue Sep 8, 2023 · 2 comments
Closed
2 tasks done

[pickers] Datepicker with html5 validation #10274

OZZlE opened this issue Sep 8, 2023 · 2 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it

Comments

@OZZlE
Copy link

OZZlE commented Sep 8, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example: N/A

Steps:

  1. Code:

    const [date, setDate] = useState('');
    
    <form>
      <DatePicker
           maxDate={dayjs()}
           inputRef={dateRef}
           name="transactions[date]"
           inputProps={{
             required: true,
             pattern: "^(MM / DD / YYYY)",
           }}
           value={date}
         />
         <button type="submit">send</button>
    </form>
    
  2. Do not pick any date just press "send"

Current behavior 😯

You can send the form without filling in date

Expected behavior 🤔

built in browser validation should prevent form from being sent but it doesn't because the value of the <input> field that datepicker has is "MM / DD / YYYY" instead of empty

"MM / DD / YYYY" should be inside placeholder attribute rather than being the value

Context 🔦

My form relies 100% on html5 validation and no js validation

Your environment 🌎

npx @mui/envinfo

  System:
    OS: Windows 10 10.0.19044
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 116.0.5845.141
    Edge: Spartan (44.19041.1266.0), Chromium (114.0.1823.106)
  npmPackages:
    @emotion/react: ^11.10.6 => 11.10.6
    @emotion/styled: ^11.10.6 => 11.10.6
    @mui/base:  5.0.0-alpha.124
    @mui/core-downloads-tracker:  5.11.16
    @mui/icons-material: ^5.11.16 => 5.11.16
    @mui/material: ^5.11.16 => 5.11.16
    @mui/private-theming:  5.11.13
    @mui/styled-engine:  5.11.16
    @mui/system:  5.11.16
    @mui/types:  7.2.3
    @mui/utils:  5.11.13
    @mui/x-date-pickers: ^6.1.0 => 6.1.0
    @types/react: 18.0.29 => 18.0.29
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    typescript: 5.0.2 => 5.0.2

USing Google Chrome Version 116.0.5845.141 (Officiell version) extended (64 bitar) on Windows 10

@OZZlE OZZlE added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 8, 2023
@zannager zannager added the component: pickers This is the name of the generic UI component, not the React module! label Sep 8, 2023
@zannager zannager transferred this issue from mui/material-ui Sep 8, 2023
@LukasTy
Copy link
Member

LukasTy commented Sep 8, 2023

Thank you for opening the issue and using the library. 🙏

The problem you are experiencing is because of an incorrect empty date value of '' instead of null.
Here is a codesandbox with your described behavior working without issues.

Closing the issue. Please feel free to reopen it if you still think that there is a problem with the mentioned behavior.

@LukasTy LukasTy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
@LukasTy LukasTy added status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 8, 2023
@LukasTy LukasTy changed the title Datepicker doesn't support html5 validation [pickers] Datepicker with html5 validation Sep 8, 2023
@OZZlE
Copy link
Author

OZZlE commented Sep 11, 2023

Great thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it
Projects
None yet
Development

No branches or pull requests

3 participants