formie icon indicating copy to clipboard operation
formie copied to clipboard

Add Date Range field type

Open mattcdavis1 opened this issue 2 years ago • 6 comments

What are you trying to do?

A date range field to allow for:

  • Improved UI for selecting a date range
  • Validation to ensure end date is after start date

What's your proposed solution?

Create a new "Date Range" field type

Additional context

No response

mattcdavis1 avatar Sep 02 '22 02:09 mattcdavis1

This allready exist.. right.. Snag_22312972

wmdhosting avatar Apr 27 '23 18:04 wmdhosting

@wmdhosting Would prefer an option for dedicated fields for each date where each one would have the same options that the current date field does (i.e. dropdown, datepicker, etc). Also, the mode/range approach doesn't allow for time selection.

mattcdavis1 avatar Apr 29 '23 18:04 mattcdavis1

Same here. I would like to see this added. Even though you can add mode => range to the Date Picker Options, it doesn't actually work when you submit the form. In Date.php there's a section that normalizes the value.

https://github.com/verbb/formie/blob/0ecab1ac258fe7689e2c4a81c34962f96772d6e4/src/fields/formfields/Date.php#L277C1-L281

flatpickr passes ranges in the format of "2023-06-18 to 2023-06-30". When Formie normalizes this value, it just returns null because it doesn't know how to handle it. This results in a blank value. I'm not even sure how this would be implemented either. The Date class defines the field as yii\db\Schema::TYPE_TIME or yii\db\Schema::TYPE_DATETIME (depending on if the field is configured as time only or date/date+time). If it did support multiple values, it would have to be changed over to TYPE_STRING or TYPE_TEXT, which might have huge refactor repercussions.

For now I think all I can do is use two fields (start date and end date), which is too bad. I wanted to be able to use the Available Days option to force ranges to be split into single week chunks.

jmariklecr avatar Jun 07 '23 16:06 jmariklecr

The same issue occurs when using mode multiple it doesn’t show any date in the submission. Will this be fixed in 2.2.0? @engram-design

Frontend: image

Submission: image

Maybach91 avatar Jan 22 '24 12:01 Maybach91

@Maybach91 It probably won't be "fixed" exactly, as we'll implement a new option for the field to use a range. The tricky part is that while you can define Flatpickr to use range or multiple from the front-end with JS, we don't know that from the back-end, where we need to normalize the value (as @jmariklecr mentions).

So not so much fixed as addressed properly.

engram-design avatar Jan 23 '24 09:01 engram-design

@Maybach91 It probably won't be "fixed" exactly, as we'll implement a new option for the field to use a range. The tricky part is that while you can define Flatpickr to use range or multiple from the front-end with JS, we don't know that from the back-end, where we need to normalize the value (as @jmariklecr mentions).

So not so much fixed as addressed properly.

Thanks! So there is also no workaround for this to make this work? @engram-design

Maybach91 avatar Jan 24 '24 12:01 Maybach91