cst989 Posted October 10 Share Posted October 10 I have a catalogue of DVDs in ProcessWire. Sometimes I know the exact date, sometimes I only know the month and year, or just the year. I'm migrating from a system that allowed me to put in the date like 00-00-1995, but PW's date fields will always default to 01-01-1995. Even if you use the date option that says "separate inputs for year, month and day" and only save year, it will still set the month and date to Jan 1st. Ideally I want it to still behave like a date field, maybe with a calendar, but at least limiting the format to correct dates, and being able to sort by it on the front end. I can think of workarounds, like having 3 separate fields and perhaps joining them together in a hidden field or in my template. But I wondered if anyone had a go-to approach that they've used for this in the past. Thanks in advance! 🙂 Link to comment Share on other sites More sharing options...
bernhard Posted October 10 Share Posted October 10 I think the simplest solution would be to use a regular text field and additionally create a hidden datetime field. Then you add a hook on saveReady that populates that datetime field via something like strtotime(...). But it depends who inputs dates... only you? Or also others? Then you need to be more careful with input and maybe provide 3 inputfields, one for day, month, year. That could also be done with a hook. 2 Link to comment Share on other sites More sharing options...
BitPoet Posted October 11 Share Posted October 11 The question prompted me to put FieldtypeSketchyDate on GitHub. It's a small module I started writing for a solution that never went anywhere, so its pretty basic. It may be a starting point though. In short, it lets you enter 2024 or 2024/10 or 2024/10/11 in the date value, and it also lets you search for 2024/10 and returns all pages with a date between 2024/10/01 and 2024/10/31 as well as those where 2024/10 was entered. So far, it just validates the formatting through the HTML pattern attribute. Proper date validation and calendar UI are still on the todo list. 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now