how to deal with recurring date ranges where the year shouldn't be present? #1256
-
I'd like to add an option that makes it so a dialog is shown every year between an adjustable date range. eg. Jan to Apr 1 or Jan 15 to Apr 15 or whatever. Pursuant to that, the date field having a year seems kinda weird. date_picker seems like the most customizable date dialog but it doesn't look like even that one will let you select yearless date ranges? What are your thoughts on how to deal with this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Based on the knowledge sources provided, there doesn't seem to be a built-in solution in Backpack for handling recurring date ranges without years or for creating yearless date ranges. The date_range and date_picker fields in Backpack are designed to work with full dates, including years. However, I can suggest a possible approach to deal with this situation:
CRUD::field([
'name' => 'start_date,end_date',
'label' => 'Recurring Date Range',
'type' => 'date_range',
'date_range_options' => [
'drops' => 'down',
'locale' => ['format' => 'MM/DD']
]
]);
This approach would require significant customization and isn't a out-of-the-box solution provided by Backpack. It would involve extending Backpack's functionality and potentially creating a custom field type. If this level of customization is crucial for your application, you might want to consider creating a completely custom solution using a JavaScript date library that supports yearless date ranges, and then integrating it with Backpack as a custom field. Remember that this is a complex requirement that goes beyond Backpack's standard functionality. You might want to reach out to the Backpack community or consider opening a feature request for this functionality if you believe it would be widely useful. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Fields|date_range PRO |
Beta Was this translation helpful? Give feedback.
-
You're right that removing the year from a date field can make things tricky when using a calendar picker. Calendar views rely on the year to correctly determine the day of the week, which makes them less practical for selecting yearless date ranges like "Jan 15 to Apr 15." The best way to handle this use case would be to create a custom field. Instead of using a calendar picker, the custom field could provide two text inputs for entering the start and end of the range in a MM-DD format. This approach avoids the confusion of irrelevant calendar years and focuses solely on capturing the day and month values. You can then add backend validations to ensure the inputs are in the correct format and handle the logic to compare dates without considering the year. Cheers. |
Beta Was this translation helpful? Give feedback.
-
Due to not activity, I will close this issue, but please feel free to re-open or create a new one if needed. Cheers. |
Beta Was this translation helpful? Give feedback.
Hi @prescriptionlifeline
You're right that removing the year from a date field can make things tricky when using a calendar picker. Calendar views rely on the year to correctly determine the day of the week, which makes them less practical for selecting yearless date ranges like "Jan 15 to Apr 15."
The best way to handle this use case would be to create a custom field. Instead of using a calendar picker, the custom field could provide two text inputs for entering the start and end of the range in a MM-DD format. This approach avoids the confusion of irrelevant calendar years and focuses solely on capturing the day and month values. You can then add backend validations to ensure the inputs…