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

Date field using dropdown display mode does not accept year input #2261

Open
jamesmacwhite opened this issue Jan 24, 2025 · 4 comments
Open

Comments

@jamesmacwhite
Copy link
Contributor

Describe the bug

When using a date field with the dropdown display mode, the input is not accepted on the front end.

In this example a date field with just the year field enabled is used. I selected 2011 from the select menu, when I submitted the form it was returned with the validation error of "Year cannot be blank"

Image

Potentially the wrong handle/name value is being used where the data is not being sent properly?

Raised from #2244

Steps to reproduce

  1. Create a date field with the dropdown display mode enabled with just the year field
  2. Attempt to submit the form with a year value selected
  3. A validation error of "Year cannot be blank" is displayed preventing the form from being submitted.

Form settings

  • Multi-page form: No
  • Submission Method: Page Reload
  • Client-side Validation: No
  • Custom Form Templates: No

Craft CMS version

5.6.1

Plugin version

3.0.19

Multi-site?

No

Additional context

No response

@engram-design
Copy link
Member

This is a bit of a limitation with the dropdown/input for a Date field, as it doesn't at the moment really handle partial dates. This is because under the hood, the value for the Date field is a PHP DateTime, and that providing just the year isn't enough to create a date. Of course we could "fudge" it a little by setting the month and day to 01, but that's not always desirable to record that.

Fixing this will almost certainly require a breaking change where we are proposing a custom DateTime model of our own to track these things individually.

So the short of it is, there's not really a method to use year, year+month combinations, it has to be "full" date, "full" time, or date + time.

@jamesmacwhite
Copy link
Contributor Author

jamesmacwhite commented Jan 24, 2025

Thanks for the info, probably worth highlighting this in the documentation at some point, that partial dates basically can't be supported under the dropdown mode currently.

The year field in the date/time field is nice because of its dynamic nature of start/end values, relative to the current year. I'll look at implementing something similar in a dropdown to workaround it or perhaps a free text field but with number validation and a range between to implement the same.

@engram-design
Copy link
Member

Yep, I've been messing around with options for the past few months, but nothing satisfying that doesn't break things. Of course, I'd rather fix this behaviour up now!

We do also have plans to modify the preset behaviour for Dropdown fields. Currently they just act as ways to preload data, but once it's in, it's essentially set. In the future, we'll have proper preset, dynamic options for this sort of scenario.

@jamesmacwhite
Copy link
Contributor Author

That's great to hear Josh, exciting developments ahead! For now I will implement a text field but with number/dynamic range validation to mimic the same offered by the date/field dropdown year field and use that for now.

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

No branches or pull requests

2 participants